创建 Windows 快捷方式并启用“以管理员身份运行”选项

And*_*sev 7 uac windows-10

在 Windows 中,我可以设置一个快捷方式来始终以管理员身份运行应用程序: 在此输入图像描述 在此输入图像描述

我需要从命令行创建这样的快捷方式。我怎样才能做到这一点?

dav*_*ham 8

StackOverflow的答案展示了如何在 Powershell 中完成此任务。没有简单的界面来添加Run as administrator标志,因此它需要翻转二进制文件中的一些位.LNK

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\7-Zip File Manager.lnk")
$Shortcut.TargetPath = "C:\Program Files\7-Zip\7zFM.exe"
$Shortcut.Save()

$bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\7-Zip File Manager.lnk")
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$Home\Desktop\7-Zip File Manager.lnk", $bytes)
Run Code Online (Sandbox Code Playgroud)