How to install a desktop shortcut (to a batch file) from a WiX-based installer that has "Run as Admi

Posted by arathorn on Stack Overflow See other posts from Stack Overflow or by arathorn
Published on 2010-04-13T20:49:52Z Indexed on 2010/04/20 18:23 UTC
Read the original article Hit count: 269

Filed under:
|
|
|
|

I'm installing a desktop shortcut (to a batch file) from a WiX-based installer -- how do I automatically configure this shortcut with the "Run as Administrator" setting enabled? The target OS is Windows Server 2008 R2, and the installer is running with elevated priveleges.

Update:
Thanks to the link provided by @Anders, I was able to get this working. I needed to do this in a C# CustomAction, so here is the C# version of the code:

namespace CustomAction1
{
 public class CustomAction1
 {
  public bool MakeShortcutElevated(string file_)
  {
   if (!System.IO.File.Exists(file_)) { return false; }

   IPersistFile pf = new ShellLink() as IPersistFile;
   if (pf == null) { return false; }

   pf.Load(file_, 2 /* STGM_READWRITE */);
   IShellLinkDataList sldl = pf as IShellLinkDataList;
   if (sldl == null) { return false; }

   uint dwFlags;
   sldl.GetFlags(out dwFlags);
   sldl.SetFlags(dwFlags | 0x00002000 /* SLDF_RUNAS_USER */);
   pf.Save(null, true);
   return true;
  }
 }

 [ComImport(), Guid("00021401-0000-0000-C000-000000000046")]
 public class ShellLink { }

 [ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("45e2b4ae-b1c3-11d0-b92f-00a0c90312e1")]
 interface IShellLinkDataList
 {
  void GetFlags(out uint pdwFlags);
  void SetFlags(uint dwFlags);
 }
}

© Stack Overflow or respective owner

Related posts about wix

Related posts about Windows