Search code examples
batch-filevbscriptdesktopshortcut

create a shortcut using vbs, set to 'run as' admin


[terse] I am looking for a method of setting a desktop shortcut to "Run As Administrator".

pseudo.code: object.Advanced = "Administrator"

[verbose] I have scoured the web and discovered how to make a batch script to gather required information for generating a 'shortcut' on a user's 'desktop'. This 'link' can sometimes need to be run as "Administrator" to perform certain actions (like clearing out TEMP locations, adding files to subfolders under %ProgramFiles(x86)%, etc.). I can have it display instructions to the script using "Run As Administrator" from the Context Menu but the less user interaction (beyond double-clicking) with the generated script file the better.


Solution

  • try with shortcutJS.bat - it can create a shortcut with "run as admin" tick from command line :

    call shortcutJS.bat -linkfile "some.lnk" -target "%cd%\some.bat" -adminpermissions yes
    

    There's no api function that can tick the 'run as admin' option. In this case I'm reading the lnk file and I'm changing the 21st byte of the file. More information can be found somewhere in this docs.