Create Shortcut With Elevated Rights

Today I needed to create a shortcut for a program in a package. not that big a challenge I thought, as I have created lots of shortcuts during my 16 years deploying Windows and related software. But then the customer said ”oh, can you set the Run as Administrator flag on that?”.

Well, never had to do that before but it turns out that PowerShell once again comes to the rescue!

We can create the shortcut like we normally do, using the WScript.Shell.CreateShortcut method, and the using the System.IO.FileStream to modify the bitstream on the shortcut that controls the elevation prompt.

The following script contains a PowerShell cmdlet that will create shortcuts with or without elevation (Run as Administrator). The last line contains the call to the cmdlet that creates a shortcut for Notepad++ that will have the Run as Administrator flag set.

2014-12-16 14_13_19-2014-12-16 14_13_31-Notepad Admin Properties2014-12-16 14_13_49-Advanced Properties

The script

 

Download the script here:

Download “CreateElevatedShortcut.zip” CreateElevatedShortcut.zip – Downloaded 283 times – 1 KB

About the Author:

Henrik Rading

One Comment

  1. Feldu34 October 15, 2015 at 15:40 - Reply

    MDT2013-U1
    Hi henrik,
    we have a specificity on the AD domain integration and wonder if it is possible to do so in MTD. Currently MDT integrates the machine on the CD of the site or one that meets at random, out this poses problems at the network level, and we definitely need to specify a DC that is on a different AD Site
    is it possible to specify in MDT him the CD on which all machines must integrate and therefore choose not to leave the MDT DC Site
    thanks advance for his answers

Leave A Comment