Kevin2341
Posts: 7
Joined: Thu Jul 26, 2018 5:15 pm

Run a few commands from an elevated command prompt on installation complete?

I have a web app which gets deployed locally with my installer which I have learned I need to run a few commands OR reboot the system afterwards to get the website working correctly otherwise a get a 502.5 server error. I have learned I can manually resolve the error by running the following commands: "net stop was /y" followed by "net start w3svc". As I stated, if the PC reboots, there is no need to run these commands.

The software which is installing will commonly be installed on a server and it'd be convenient for the user to not require a reboot after my application has finished installing, therefore I'd prefer not to prompt the user to reboot. I attempted to make a custom action using the "Run PowerShell inline script" option, but it does not seem to execute the script correctly as I get the 502.5 server error immediately after installation. Running the commands mentioned previously in an elevated command prompt causes the website to work as it should.

Something else to note is that I do have the installer configured in the "Install Parameters" area with the "Run as administrator" box checked. Is there something I can do to either debug the script, force the script to run in admin mode, or if there is a way to do this built into Advanced Installer that doesn't force me to manually run this script, that'd be great.
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Run a few commands from an elevated command prompt on installation complete?

Hello,

I am not so sure why this happens. Having the "Run as administrator" option enabled in "Install Parameters" page means that the whole installation process will run elevated and so all of its child processes (i.e. the custom action processes).

Can you try to create a short BAT file with the related commands inside and add the BAT as a custom action and see if this helps?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Kevin2341
Posts: 7
Joined: Thu Jul 26, 2018 5:15 pm

Re: Run a few commands from an elevated command prompt on installation complete?

Seems like that is working better now. Any reason why running it as a batch file would have a different output than as a script?
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Run a few commands from an elevated command prompt on installation complete?

I cannot say why. But maybe you could try to debug your PowerShell script code and see if it throws any exception or error.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Kevin2341
Posts: 7
Joined: Thu Jul 26, 2018 5:15 pm

Re: Run a few commands from an elevated command prompt on installation complete?

I appreciate the help. Another question if you don't mind.

So, I'm the website I'm installing is written in .Net Core, which has a pretty specific installation process according to this guide: https://docs.microsoft.com/en-us/aspnet ... etcore-2.1

Essentially the process is such that you install the IIS Windows Features, then you install the .Net Core Hosting Bundle, then you create your website. I've found that the scripts I need to be ran need to be done after all of these steps (the commands are just "net stop was /y" and then "net start w3svc"). The way I had to configure my project was such that the hosting bundle gets installed in the Post-install phase (unless there is some way to get this to install right after the Windows Features get installed).

The way I see it right now, if I could get my script to run right after the .Net Core Hosting Bundle is finished installing, that would fix my issue. Are you aware of any way I could do this? The only option I see right now that doesn't involve the PC being rebooted is instructing the user after the installation is done to locate the script and just run it manually (which is still preferable to rebooting as it's not overly complex, but human error dictates that it will get skipped and people will be complaining that things aren't working :-))
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Run a few commands from an elevated command prompt on installation complete?

Hello,

I apologize for the delayed reply.

To fulfill your requirements you should try just to add your ".Net Core Hosting Bundle" prerequisite as a pre-install prerequisite. This will also change your setup package type into an EXE one.

If you need an MSI setup package type, then as another workaround you can try to create a separate setup project which will only install and configure your web site and add this setup package and the ".Net Core Hosting Bundle" package as feature-based prerequisites to a third wrapper setup project. The prerequisites should be added in the order you want them installed.

Let me know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”