Answered by:
Can an MSI create a shortcut that always runs as administrator?
Question
-
I'm authoring an MSI package using WiX, and want to create a shortcut in the Start Menu that has the "Run as Adminstrator" attribute set. Anyone know if this is possible? I can't see anything in the documentation. It seems to me that if I can set this flag after the fact using the properties page for the shortcut I should be able to get the installer to do it.
Note that I can't just add a manifest to the target of the shortcut since the shortcut just runs Notepad on a file that I've installed. The file is a service configuration file so is not writable by ordinary users.
Thanks in advance,
ColinMonday, September 17, 2007 3:53 PM
Answers
-
Not a direct answer to your question (w/r to Wix), but I'm guessing would need to write a custom action to do this.
See MSDN for IShellLink, IShellLinkDataList, and SDLF_RUNAS_USER (which seems to be the flag corrosponding to "Run as Administrator" in the shortcut advanced properties page. Flag would behave differently on pre-Vista.)
Another option which is probably cleaner is to make a quick little exe, manifested with requireAdministrator, which invokes notepad on the configuration file. This would involve an extra (albeit tiny) executable, but is probably less work than writing the custom action.
Monday, September 17, 2007 7:35 PM -
If you look at the contents of the Shortcuts table in the MSI documentation, you'll see that there's no data in that table for "Run As". Like David said, "Run As" isn't an attribute of the shortcut, it's an attribute of the Shell Link object behind the shortcut. You'll have to put code into a DLL and call that code from a custom action.
So the answer to the question in the subject is "Yes"--but you have to do all the work (other than having the .MSI call the custom action) yourself.
Wednesday, September 19, 2007 12:44 AM
All replies
-
Not a direct answer to your question (w/r to Wix), but I'm guessing would need to write a custom action to do this.
See MSDN for IShellLink, IShellLinkDataList, and SDLF_RUNAS_USER (which seems to be the flag corrosponding to "Run as Administrator" in the shortcut advanced properties page. Flag would behave differently on pre-Vista.)
Another option which is probably cleaner is to make a quick little exe, manifested with requireAdministrator, which invokes notepad on the configuration file. This would involve an extra (albeit tiny) executable, but is probably less work than writing the custom action.
Monday, September 17, 2007 7:35 PM -
If you look at the contents of the Shortcuts table in the MSI documentation, you'll see that there's no data in that table for "Run As". Like David said, "Run As" isn't an attribute of the shortcut, it's an attribute of the Shell Link object behind the shortcut. You'll have to put code into a DLL and call that code from a custom action.
So the answer to the question in the subject is "Yes"--but you have to do all the work (other than having the .MSI call the custom action) yourself.
Wednesday, September 19, 2007 12:44 AM -
Thanks for the replies. I guess I'll be writing a custom action...
Wednesday, September 19, 2007 7:34 AM -
I would like to note that having your shortcut point to an exe manifested with requestedExecutionLevel of requireAdministrator, and launches notepad on the configuration file requires only a few lines of actual code and relies only on well-understood behavior.
I'd say that option is probably easier, cleaner, and safer than writing a custom action to make a weird shortcut file.Wednesday, September 19, 2007 10:00 PM -
Yes, I'd agree with David. A stub executable is a much better design than trying to bodge a shortcut's compatability settings (which may well break in future versions of Windows).Thursday, September 20, 2007 8:44 AM
-
Though the manifested-executable approach
1) Doesn't really address the subject of the thread, which is about a shortcut that causes something to RunAs, rather than having the "something" itself set to RunAs
2) Precludes having an executable that can run as anyone else, so it won't work if the same .EXE needs to be available to admin users with elevated privileges and to 'regular' users without elevated privileges
Friday, September 21, 2007 6:56 PM -
Thanks for all the replies. I ended up going with the manifested executable approach, the main reason being that it let me do a couple of other things I realised I needed to do:
1) My executable not only opens the configuration file in notepad, it can also wait for it to close again and then restart the service so that it picks up the new configuration.
2) I can use the same executable from the installer as a custom action, to allow the installer to edit the configuration before the service is started.
Now if I could only figure out a way of getting the notepad window to appear in front of the installer GUI instead of behind it...
Monday, September 24, 2007 7:38 AM -
Hi,
I am using Installshield 2008 to modify and build the .MSI as per client requirements. I am able to install/uninstall the application successfully on XP and VISTA (UAC enabled/disabled)
After application gets installed, double click on desktop shortcuts / system tray icon shortcut is not launching the app and everytime user has to right click -> select "Run as Admin" option to run it on VISTA when UAC is enabled.
I gone through your posts but I could not understand how to make manifest executable to resolve this issue which is highest priority for me
Can you show me some sample script and how to attach it with my .ISM file?Can any one of you guide me on this as soon as possible?
Many thanks in advance if anyone can help on this.Tuesday, June 24, 2008 4:56 AM -
Check the following article on how to add a manifest to your .net application
http://msdn.microsoft.com/en-us/library/bb756929.aspx
DanFriday, October 23, 2009 8:46 PM