windows – 如何使用Powershell创建Run As Administrator快捷方
发布时间:2020-12-13 20:34:19 所属栏目:Windows 来源:网络整理
导读:在我的PowerShell脚本中,我创建了一个.exe的快捷方式(使用类似于 this question的答案): $WshShell = New-Object -comObject WScript.Shell$Shortcut = $WshShell.CreateShortcut("$HomeDesktopColorPix.lnk")$Shortcut.TargetPath = "C:Program Files (
在我的PowerShell脚本中,我创建了一个.exe的快捷方式(使用类似于
this question的答案):
$WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$HomeDesktopColorPix.lnk") $Shortcut.TargetPath = "C:Program Files (x86)ColorPixColorPix.exe" $Shortcut.Save() 现在,当我创建快捷方式时,如何添加到脚本以使其默认以管理员身份运行?
这个答案是PowerShell翻译的一个很好的答案这个问题
How can I use JScript to create a shortcut that uses “Run as Administrator”. 简而言之,您需要以字节数组的形式读取.lnk文件.找到字节21(0x15)并将位6(0x20)更改为1.这是RunAsAdministrator标志.然后你将字节数组写回.lnk文件. 在您的代码中,这将是这样的: $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$HomeDesktopColorPix.lnk") $Shortcut.TargetPath = "C:Program Files (x86)ColorPixColorPix.exe" $Shortcut.Save() $bytes = [System.IO.File]::ReadAllBytes("$HomeDesktopColorPix.lnk") $bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON [System.IO.File]::WriteAllBytes("$HomeDesktopColorPix.lnk",$bytes) 如果有人想要更改.LNK文件中的其他内容,您可以参考official Microsoft documentation. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 如何设置apt-cyg的代理?
- 如何减少Windows Azure网站上托管的Orchard CMS站点的内存消
- windows-server-2008 – 本地组策略在Dc中做了什么?
- 安装WindowsXP更新后WCF服务错误
- 如何在Windows下安装ant contrib?
- windows-server-2008 – 确定哪个应用程序池正在使用CPU /内
- microsoft-office-2010 – Office 2010部署
- windows – 一个好的注册表清理器的任何建议?
- .net – 从不同的文件夹加载一个DLL引用?
- windows – 命令行工具查找Dll依赖关系[已关闭]