views:

115

answers:

2

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

+2  A: 

Hi,

You will need to create a manifest file for your application in order to get it to request run as an administrator privileges. Here is a nice tutorial you can follow.

Enjoy!

Doug
+1 for the nice tutorial. Yes I already know about the manifest file, as well as another option (see my comment below my question), but I was still wondering if was possible to set that *new* property on the shortcuts.
JohnB
FYI, here's a video tutorial about the manifest: http://channel9.msdn.com/Blogs/jmazner/How-To-Tell-Vistas-UAC-What-Privelege-Level-Your-App-Requires. He mentions the *shortcut* option, but re-iterates that **the *UAC Manifest* is the correct solution**.
JohnB
Create and Embed an Application Manifest (UAC): http://msdn.microsoft.com/en-us/library/bb756929.aspx
JohnB
+3  A: 

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

Anders
Not very useful until you show him how to get the interface declarations into his C# program.
Hans Passant
@Hans: I was thinking of embedded the C++ DLL into my C# program; is there a better way? @Anders: thank you for pointing out this solution. I agree with you that Doug's answer is the correct approach to this UAC issue.
JohnB