Run inline PowerShell script before starting a service - Advanced Installer Community
markus.kastner
Posts: 2
Joined: Tue Jul 04, 2023 1:35 pm

Run inline PowerShell script before starting a service

I have to change a config file before the service gets started. In the "Install execution stage" I did a right klick, followed "Show Standard Action"->"Add Resources"->"Install Services" and "Show Standard Action"->"Add Resources"->"Start Services". I placed my inline script between InstallServices and StartServices, but when I save this and reopen it, it is gone and the installation starts the service before the script is executed.

Script settings are:
Execution Time
"When system is being modified (deferred)"
Execution Options
"Run under the local system account" & "Fall installation if..."
Execution Stage Condition
"Install" & "Maintenance"
"Condition:"

Code: Select all

 (VersionNT > 501) OR (VersionNT = 501 AND ServicePackLevel >= 2)

Did I miss something?
Attachments
After saving, closing and reopening
After saving, closing and reopening
Capture2.PNG (10.41 KiB) Viewed 8059 times
After adding the steps
After adding the steps
Capture1.PNG (12.16 KiB) Viewed 8059 times
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Run inline PowerShell script before starting a service

Hello Markus and welcome to our forums,

This is indeed quite strange!

Normally, I would say that this is simply a UI glitch, but in your case it looks like it also affects the actual sequence of the actions.

if possible, could you please go to "Table Editor" --> "InstallExecuteSequence" table and check the order in there to make sure the custom action is scheduled before the "Start Service" standard action?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
markus.kastner
Posts: 2
Joined: Tue Jul 04, 2023 1:35 pm

Re: Run inline PowerShell script before starting a service

Hello Catalin,

Unfortunately I only have a professional license, so no table editor available.

Best regards,
Markus
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Run inline PowerShell script before starting a service

Hello Markus,

The fact that your UI changes back is indeed a confusing thing which I will try to discuss with our team and see if we can improve it.

However, the custom action is correctly scheduled as per my tests.
Screenshot_33.png
Screenshot_33.png (4.01 KiB) Viewed 6838 times
Screenshot_34.png
Screenshot_34.png (4.99 KiB) Viewed 6838 times

As you can see, the PowerShell custom action is actually scheduled between the "InstallService" and "StartService" as we initially scheduled it.

If possible, could you please build your project and check the MSI database using Orca (this comes by default with the Windows SDK if I remember correctly)?

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

Return to “Common Problems”