Search code examples
c#windows-7uacshortcut

Create shortcuts programmatically from C# and set "Run as administrator" property


I already know how to create shortcuts programmatically from my C# applications using IWshRuntimeLibrary and WshShellClass. Or I could use IShellLink.

Now, if the user's PC is running Windows Vista or Windows 7, I would like to be able to set the "Run as administrator" property of that shortcut programmactically as well.

Is that possible? If so, how?

alt text


Solution

  • While Doug's answer is the correct solution to this problem, it is not the answer to this specific question...

    To set that property on a .lnk, you need to use the IShellLinkDataList COM interface. The great Raymond Chen has c++ sample code on his blog for this