We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Darion
Posts: 5
Joined: Wed Nov 27, 2019 9:51 am

Run bat as admin during/after installation

Hi fellow users and devs, I'd like to make the installer to run a bat file during or after installation. Seems no big deal except the bat would fail if it's not runned as admin. So I've tried:

1. Adding the bat file as one of the installation files;
2. In the "Finish Actions - Launch Application" section of the "First Time Install - ExitDialog", set the application as the bat file with "Run as Administrator" checked;
3. In the "Install Parameters" tab, check "Run as Administrator" under "Installation Options", and set the "Execution level" to the highest;
3. Run the installer as admin.

Basically I checked everything that's admin related, but the bat would still fail cause it has no admin privilege. Can't figure out why this is not working as intended, any help would be appreciated.
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Run bat as admin during/after installation

Hello,

I have tested this and everything worked as expected on my side.

When the setup ended, I have selected the "Launch my application" checkbox and the .BAT file was executed as expected, with administrator rights. The UAC showed up, asking if I want to run the .BAT file as administrator:
RunAsAdmin.png
RunAsAdmin.png (25.88 KiB) Viewed 7515 times


After pressing "Yes", the .BAT file was successfully launched as administrator:
AdminCMD.png
AdminCMD.png (11.57 KiB) Viewed 7515 times

With that in mind, could you please give me some more details about your scenario? For instance, what version of Advanced Installer are you using (I've tested this using the latest version of Advanced Installer, 16.7)?

In addition to that, have you tested your .BAT file outside of Advanced Installer? If so, did it work as expected?
but the bat would still fail cause it has no admin privilege.
Could you please give me some more details about this as well? What are you trying to achieve through the .BAT file that it fails without admin privileges?

Looking forward to hearing from you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Darion
Posts: 5
Joined: Wed Nov 27, 2019 9:51 am

Re: Run bat as admin during/after installation

Hi Catalin,

Thanks for the follow-up.

I'm running Advanced Installer v16.5, and the .bat file I use basically changes Data Execution Prevention policy to be able to whilelist my application. It works fine when directly runned as admin outside the installer.

Code: Select all

@ECHO OFF
ECHO Changing DEP policy...
call bcdedit.exe /set {current} nx OptOut && color 0A && echo DEP policy changed to allow exceptions. || color 0C && echo Rerun as ADMIN.
PAUSE
EXIT
I think the installer wasn't able to get admin privilege the whole time, because it also fails to write/delete registry keys under HKLM, only able to operate keys under HKCU. BTW I turned off UAC warning on my PC as they are pretty annoying to me, but I think this isn't the issue here.
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Run bat as admin during/after installation

Hello,

Thank you for the explanation.

I have further investigate this and I think I found the root cause of this problem.

At a first glance, I found out that the bcdedit.exe is found in C:\Windows\System32 location.
bcdedit.png
bcdedit.png (26.95 KiB) Viewed 7498 times

If you go to C:\Windows\SysWOW64 location --> open a cmd prompt from there and type in, for instance:

Code: Select all

bcdedit.exe /enum {current}
you will get the following error:
'bcdedit.exe' is not recognized as an internat or external command, operable program or batch file.
This is the same error I've been getting when trying to run the .BAT file from the Finish Dialog (to test your scenario).

Even though you are echo-ing the "Rerun as admin" message, that does not seem to be the case.

Long story short, the problem here is the fact that your setup, being a 32-bit setup ("Install Parameters" page --> "Package Type" --> "32-bit package") installed on a 64-bit machine, the redirection comes in place and the setup tries to run your .BAT file using the 32-bit cmd executable which can be found in the "SysWOW64" folder, instead of the one located in the "System32" folder.

When you right click on the .bat file --> "Run as administrator", the 64-bit cmd executable is used by default (since you are on a 64-bit machine) (from System32 folder) and this is why it works as expected.

With that being said, in order to avoid such a behavior, please go to "Custom Actions" page and create a "Launch File" custom action as it follows:
CA.png
CA.png (129.96 KiB) Viewed 7498 times


If your .BAT file is named differently, simply type "[" in the "File to launch:" field --> "File" and then, in the spawned dialog, select your .BAT file.

Hope the explanations helped and things are more clear now.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Darion
Posts: 5
Joined: Wed Nov 27, 2019 9:51 am

Re: Run bat as admin during/after installation

Hi Catalin,

Thank you so much. Never thought that was the problem, everything works like a charm now.
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Run bat as admin during/after installation

You are always welcome!

I am really glad I could help.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”