0

I developed a workaround for WinXP legacy software (code/project not available, its very old!) that allows it to run in Windows 10. The workaround essentially consists of an Inno script setup that: 1) Runs the software's XP installer (prompts for admin), and 2) Runs BATCH file to copy files "comctl32.dll/.ocx" to the Windows/SysWOW64

The intent is to run this installer silently on client PCs, and installation/copy of files are fine, but my main problem is that the programs installed must be "Run As Admin" at least once, in order to work subsequently for local admin & standard users.

enter image description here

So currently my silent installer / batch does everything fine, but I still have to right-click all those programs and do Run As Admin once (which defeats the purpose of creating that installer/script if I have to do this with all my machines!). So I'm thinking that I should add to my Batch file to run the program (as admin), then force-close.

Any suggestions on how I can script this? FYI, I considered "nircmd" but I think our scanners flagged it and it was gone from my PC before I could try anything with it. ^_^

The user accounts of these PCs are always set to "local admin", but not any admin level higher than that. I really don't know whats going on in the background when the programs start with Run as Admin (did I mention no access to code/project? ^_^)

Here is the Batch file I wrote that runs after that XP installer. This essentially does some of that extra workaround file copy and tries to run the program, taskkill after... Do you think this is headed in the right direction?

    ECHO
    TITLE "C Win10 Installer"
    COPY "c:\temp\Cwin10\Cicon.ico" "C:\Program Files (x86)\ABC\Cfolder\C.ico"
    COPY "c:\temp\Cwin10\comctl32.dll" "C:\Program Files (x86)\ABC\Cfolder\comctl32.dll"
    COPY "c:\temp\Cwin10\comctl32.ocx" "C:\Program Files (x86)\ABC\Cfolder\\comctl32.ocx"
    COPY "c:\temp\Cwin10\CDM20830_Setup.exe" "C:\Program Files (x86)\ABC\Cfolder"
    XCOPY "c:\temp\Cwin10\ref" "C:\Program Files (x86)\ABC\Cfolder\ref" /i /s
    COPY "C:\Program Files (x86)\ABC\Cfolder\Strip.ocx" "C:\Program Files (x86)\ABC\Cfolder\app\Strip.ocx"
    RUNAS /env /user:Administrator "C:\Program Files (x86)\ABC\Cfolder\app\App.exe"
    TASKKILL /F /im App.exe
    DEL "C:\temp\Cwin10\Cicon.ico"
    set folder="C:\temp\Cwin10"
    cd /d %folder%
    for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)

Also FYI, I do have this added to the top of my batch How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?


UPDATE: Modified to register the DLLs in INNO instead, here's where I am currently. I am using the Shortcut workaround to run the application as Admin once, so subsequent runs will work... however I want to TASKKILL so it runs for a quick sec and closes immediately, then runs the next two applications.

However what it really is doing is running the application and does nothing. When I close, then TASKKILL comes and cannot find the running process. Any suggestions to RUN then TASKKILL in one second?

ECHO
TITLE "C Win10 Installer"
"C:\temp\Cwin10\BexeShortcut.lnk"
TASKKILL /F /im B.exe
"C:\temp\Cwin10\EexeShortcut.lnk"
TASKKILL /F /im E.exe
"C:\temp\Cwin10\Cexe.lnk"
TASKKILL /F /im Cexe.exe
set folder="C:\temp\Cwin10"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
joshjayse
  • 77
  • 2
  • 2
  • 16
  • 1
    To use RUNAS in the batch file you would have to know the Administrator password and include it on the same line. I believe that if you do Run As Administrator on the INNO program itself then the INNO program runs as administrator and all programs that are run from within the INNO installer, by default, run as the CurrentUser which would be the Administrator. So you wouldn't need to use RUNAS in the batch file. – thx1138v2 Jul 27 '17 at 20:20
  • I see some problems in your batch file. You aren't registering the DLL's. INNO can do everything you are doing in the batch file plus register the DLL's. – thx1138v2 Jul 27 '17 at 20:26
  • Thx, I did correct the DLL and did add to the [FILES] line in INNO. As for 'code' RUNAS /env /user:Administrator "C:\Program Files (x86)\ABC\Cfolder\app\App.exe" 'code', so I am running the Batch file as current user 'code' Filename: "c:\temp\Cwin10\cleanup.bat"; StatusMsg: "Copying additional files..."; Flags: hidewizard runascurrentuser waituntilterminated 'code'... I did notice in CMD in Admin mode, it is asking for a password... I can't get it to run even using RUNAS /env "C:\Program Files (x86)\ABC\Cfolder\app\App.exe". Thoughts? – joshjayse Jul 27 '17 at 20:46
  • @thx1138v2, disregard that top part... I just realized how to cmd to run a shortcut with Run As Admin... but the program starts and I want to close immediately. Any reason why TASKKILL is not working? It seems that it only runs after I close App.exe, which at that point is redundant. I simply want to run the file once for a quick sec (to save the Run As Admin), and close immediately. – joshjayse Jul 27 '17 at 23:00
  • I'm guessing App.exe needs a little time to fully load and initialize. Assuming you are using the batch file to run App.exe, put a TIMEOUT command between the App.exe invocation line and the TaskKill line. – thx1138v2 Jul 28 '17 at 11:37
  • 1
    You might also look at using START in the batch file to run App.exe. The /B switch of the START command will run it without a new window and it will run without waiting for App.exe to terminate. So it would immediately start processing the TIMEOUT batch line. You might have to play with the TIMEOUT delay to give it enough time to initialize. Be aware that if you use the /B switch, you'll need to kill App.exe with task manager while you are debugging. – thx1138v2 Jul 28 '17 at 11:47
  • @thx1138v2, START with /b does work! I did have hiccups because I was specifying in the 'code' START /B "c:\---\app.exe" 'code' and the application wouldn't run. but then I just changed to START /b APP.EXE and works great! no timeout needed, but definitely START /B resolved it! thx sir! P.S... if you copy/paste the response as an answer, I will certainly give you props/credit for it. – joshjayse Jul 28 '17 at 16:08

1 Answers1

1

In batch file:

START "" /B App.exe
TIMEOUT /t 1
TASKKILL /F /IM App.exe

Thanks.

thx1138v2
  • 566
  • 3
  • 6