Can I prevent installation if setup was not run as administrator? - Advanced Installer Community
AndreG
Posts: 57
Joined: Tue Jun 10, 2014 11:41 am

Can I prevent installation if setup was not run as administrator?

My installation package configures a number of Windows services, and I have the Installation Parameters configured with "Run as administrator" enabled, but unless I still launch the setup file with a "Right click > Run as admin", my services installation fails.

I've searched the forums for similar issues, but each of them is in a specific environment or for a specific type of installation.. Since I'm unable to check or modify the environment for our customers before launching the setup, I have one simple question: Can I stop the setup wizard before it tries to install services if the current user does not have the required access?
AndreG
Posts: 57
Joined: Tue Jun 10, 2014 11:41 am

Re: Can I prevent installation if setup was not run as administrator?

Hmm.. Well here's something weird, I decided to rely on a batch file to check administrative access before the install. So, I created a file that contains nothing more simply..

Code: Select all

@net session 1>nul 2>nul
..and included it as a temporary file in my setup. Testing this file on it's own, if I run it from a normal command prompt, it fails and I get an "errorlevel" of "2". From an elevated command prompt, it succeeds and I have an "errorlevel" of "0".

After this, I added this file to a "Launch EXE With Working Directory" custom action and (due to needing to wait for setup package file extraction) set it to the first action after "Add Resources". It's rules are configured to "Wait for custom action to finish before proceeding" and "Fail installation if custom action returns an error". My initial thought was that if this fails, my installation fails and the file extraction process would roll back..

However, now when I run this same setup package on a PC that was installing my service then failing to start it afterwards, instead it installs and runs correctly.. Even without me needing to use "Run as administrator" on the setup executable. So now I'm stuck in a "it works! but I don't know why!" situation..

I would still prefer a solution that checks for admin rights before even configuring the application and clicking "Install", so this doesn't resolve my initial query, I'm just sharing it for future reference.
korr
Posts: 48
Joined: Tue Sep 09, 2014 3:13 pm

Re: Can I prevent installation if setup was not run as administrator?

I don't work for AI, but have you tried the Checkbox "Run only if user has administrator privileges" on the Launch Conditions page?
AndreG
Posts: 57
Joined: Tue Jun 10, 2014 11:41 am

Re: Can I prevent installation if setup was not run as administrator?

korr wrote:I don't work for AI, but have you tried the Checkbox "Run only if user has administrator privileges" on the Launch Conditions page?
To be honest, I was under the impression the "Launch Conditions" page applied to the installed application, not the setup package itself.. Possibly because the "Installation Parameters" options in the "Package Definition" section already had "Run as administrator" selected, but after reading up a bit more in the user manual, it seems I was mistaken.

Removing my batch file and enabling that option seems to have sorted this out now. I'll be passing this onto our support team tomorrow after a quick "what's new" meeting, so I'll see if they have any issues with the installation and leave feedback later this week. Thanks for point that out Korr.

Just out of curiosity, could anyone perhaps explain why these two options exist in different options pages? How do they differ?
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Can I prevent installation if setup was not run as administrator?

Hello Andre,

The "Run as administrator" option from "Install Parameters" page will add capability to the EXE setup package to run elevated from the beginning (when the EXE is launched the UAC will prompt you for elevation).

The "Run only if user has administrator privileges" launch condition will add capability to the setup package to check the current user rights (at install time). If the current launching user doesn't have admin privileges a warning will be displayed and the setup will end.

If you have any further questions just let us know.

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

Return to “Common Problems”