【发布时间】:2015-05-13 21:39:43
【问题描述】:
在我的 PowerShell 脚本中,我创建了一个 .exe 的快捷方式(使用类似于 this question 的答案):
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk")
$Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe"
$Shortcut.Save()
现在,当我创建快捷方式时,如何添加到脚本以使其默认以管理员身份运行?
【问题讨论】:
-
一定要阅读上面链接的问题 Nathan。要将代码转换为 PowerShell: $file = "$Home\Desktop\ColorPix.lnk"; $bytes = [System.IO.File]::ReadAllBytes($file); $bytes[0x15] = $bytes[0x15] -bor 0x20; #Set RunAsAdministrator [System.IO.File]::WriteAllBytes($file, $bytes);使用 –bor 设置 RunAsAdministrator 选项,使用 –bxor 取消设置。
标签: windows powershell command-line administrator desktop-shortcut