shelmers
Posts: 63
Joined: Thu Sep 03, 2009 9:02 pm
Location: Andover, Massachusetts USA

Setting "Run as Admin" for third-party exe

Our install package include two .exe files written by another vendor. I need the installer to set the "Run as Administrator" flag for these two executables. I found this thread http://www.advancedinstaller.com/forums ... 64&p=19243, but the technique listed there only appears to work if I am the developer of the apps and can build a manifest file for them.

How can I set admin rights for these two .exe files?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Setting "Run as Admin" for third-party exe

Hi,

I'm not sure I understand how you are using these EXE files. Can you please give me more details? Are you launching them during install or you are installing them on the machine so the user can launch them manually?

For the first case you can try using the runas command to launch the files. For example, if you are using an "Exe with working Dir" custom action the "Full Path" field in the Custom Action Properties page can be set to something like this:

Code: Select all

[SystemFolder]cmd.exe /C runas /user: localmachinename \administrator "[APPDIR]My File.exe"
For the second case (the user needs to run the files as an Administrator), you can try creating wrappers which launch the files as an Administrator (the installer cannot affect this behavior).

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
shelmers
Posts: 63
Joined: Thu Sep 03, 2009 9:02 pm
Location: Andover, Massachusetts USA

Re: Setting "Run as Admin" for third-party exe

My goal is for the user to be able to run the two exe files after the installation. But for Vista or Win7, I want the programs to run as admin without requiring the user to know how to do that.

What I'm looking for is a way for the installer to set whatever flag is set when I manually do these steps when running Vista:
  • right click on the exe file
  • select Properties
  • click the Compatibility tab
  • check Run as administrator.
Thanks
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Setting "Run as Admin" for third-party exe

Hello,

Please note that the flag you are referring to still exhibits the behavior you are trying to avoid, meaning it will still ask the user to grant your application permissions. This also happens if this is trying to be set from within the application's manifest.

This being said, to check that flag, you need to create a value to the following location:

Code: Select all

HKEY_USERS\[UserSID]\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
The value's name must be the full path to the executable you are trying to set, whilst the value's data must be set to "RUNASADMIN"

Attached is a sample project that sets the "Run this program as administrator" for the Advanced Updater.

Regards,
Gabriel
Attachments
test.zip
(2.16 KiB) Downloaded 659 times
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
shelmers
Posts: 63
Joined: Thu Sep 03, 2009 9:02 pm
Location: Andover, Massachusetts USA

Re: Setting "Run as Admin" for third-party exe

That's what I was looking for! Searching a bit further, it looks like I can set it for all users by substituting HKLM for HKEY_USERS\[UserSID].

Thanks, Gabriel.
shelmers
Posts: 63
Joined: Thu Sep 03, 2009 9:02 pm
Location: Andover, Massachusetts USA

Re: Setting "Run as Admin" for third-party exe

I'm doing some further testing on this topic and find that the appcompat key is actually installed here by Vista

Code: Select all

HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
My question is this: what is the difference between your suggestion of

Code: Select all

HKEY_USERS\[UserSID]\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
and the HKCU location? Does it affect system operation in any way?

Thanks
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Setting "Run as Admin" for third-party exe

Hello,

Writing to this location should not affect the system in any way. However we did not find any official documentation on this key so there are no guarantees.

We are not aware of any difference between writing the setting to HKCU and HKEY_USERS except the obvious one of per-user/per-machine setting.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
shelmers
Posts: 63
Joined: Thu Sep 03, 2009 9:02 pm
Location: Andover, Massachusetts USA

Re: Setting "Run as Admin" for third-party exe

I just want to clarify your last sentence: aren't both HKCU and HKEY_USERS/[UserSID] per user? Only HKLM is per machine. Correct?
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Setting "Run as Admin" for third-party exe

Hello,
I just want to clarify your last sentence: aren't both HKCU and HKEY_USERS/[UserSID] per user? Only HKLM is per machine. Correct?
Oops, I am sorry, I meant HKLM.

Note that HKCU is a subkey of HKEY_USERS, which contains a list of all HKCUs of the users that are currently logged on to the system. So there should be no difference since the two keys( HKCU and HKEY_USERS/[UserSID]) are one and the same. You can test this by creating a key under HKCU. It will immediately be reflected in the HKEU_USERS/[UserSID] tree (and viceversa).

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”