Hi,
While creating / editing a shortcut to a program, is there a way to access the shortcut advanced part in order to specify the "Run as admin" option ?
Thanks in advance
Unfortunately, the WIL shortcut functions do not support setting 'run as admin'. Its not as simple as it may first appear.
It is the responsibility of an application to elevate using a manifest. Why do you need to create a shortcut to elevate? Does the application you are trying to launch not have a manifest?
Apparently IShellLinkDataList can be used to mark a shortcut file as requiring elevation. Unfortunately the IShellLinkDataList interface inherits from the IUnknown interface, which rules out COM automation in WinBatch. WinBatch requires an IDispatch interface. (
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774916(v=vs.85).aspx)
One possible workaround is to flip a bit in the .lnk file. Apparently when you tick the "run as administrator" box in the Advanced tab of the Shell Properties box, or when you use IShellLinkDataList to set the flags to include SLDF_RUNAS_USER, you're basically just setting one bit in the file. It's byte 21, and you need to set the 0x20 bit on. Reference:
http://stackoverflow.com/questions/11162802/how-can-i-use-jscript-to-create-a-shortcut-that-uses-run-as-administrator ( sorry no WIL code sample to handle this ).
The solution I prefer is to create a simple WinBatch script which uses ShellExecute with "runas" verb to launch your application as an Administrator. Your shortcut can then point to this wrapper instead of the actual application.