AnswerBun.com

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"
$Shortcut.Save()

$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

Windows 10 search within images

2  Asked on February 14, 2021

     

Connection refused, but port is open

1  Asked on February 12, 2021 by gxlg

         

Boot m.2 SSD PCIe – Gigabyte mobo and B85M chipset

1  Asked on February 12, 2021 by pedro77

       

Setting up ESS (R)

1  Asked on February 11, 2021 by evangelos-con

   

Headphones not working on Ubuntu20.04 LTS

0  Asked on February 11, 2021 by codeforfun

     

Is it possible to make HD / SSD with Windows 10 from an old PC bootable on USB?

0  Asked on February 11, 2021 by guilherme-taffarel-bergamin

         

Ask a Question

Get help from others!

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