Create Windows shortcut with "Run as administrator" option enabled

Super User Asked on January 1, 2022

In Windows I can set up a shortcut to run application always as administrator:
enter image description here
enter image description here

I need to create such shortcut from the command line. How can I do that?

2 Answers

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

this also changes 21st byte of the file. More information can be found somewhere in this docs.

Answered by npocmaka on January 1, 2022

A StackOverflow answer shows how to accomplish this in Powershell. There's no easy interface to add the Run as administrator flag, so it involves flipping a bit in the .LNK binary file.

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$HomeDesktop7-Zip File Manager.lnk")
$Shortcut.TargetPath = "C:Program Files7-Zip7zFM.exe"

$bytes = [System.IO.File]::ReadAllBytes("$HomeDesktop7-Zip File Manager.lnk")
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$HomeDesktop7-Zip File Manager.lnk", $bytes)

Answered by davidmneedham on January 1, 2022

Add your own answers!

Related Questions

Full screen window command from Linux terminal?

1  Asked on December 29, 2021 by jon-d


Wifi connection drops multiple times a day

2  Asked on December 29, 2021 by cubi73


Smart Error BIOHD-8 on boot

1  Asked on December 29, 2021 by usersuper29


gcc: fatal error: no input files

2  Asked on December 29, 2021 by pcheck


Reboot and select proper boot device?

1  Asked on December 29, 2021 by el-jimmer


USB webcams with capture buttons

1  Asked on December 29, 2021


2nd HDD not detecting in BIOS

2  Asked on December 29, 2021 by harist0x


Increase a certain cell reference by 1

1  Asked on December 29, 2021 by rafalmcdragon


bootrec /rebuildbcd finds “0” Windows installations

0  Asked on December 27, 2021 by edualvarado


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP