【发布时间】:2018-10-01 07:58:36
【问题描述】:
我正在尝试创建一个需要管理员权限的快捷方式...我在互联网上找到了此代码,但它是在 powershell 中编码的...我对其进行了测试!但我在 python 中需要它我如何用 python 做同样的事情
powershell 代码:
将 .lnk 文件作为字节数组读取。定位字节 21 (0x15) 和 将位 6 (0x20) 更改为 1。这是 RunAsAdministrator 标志。然后 您将字节数组写回到 .lnk 文件中。
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk")
$Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe"
$Shortcut.Save()
$bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\ColorPix.lnk")
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$Home\Desktop\ColorPix.lnk", $bytes)
这是我的python代码:
filename = r'C:\Users\root\Desktop\qassam.lnk'
with open(filename, "rb") as f2:
while True:
current_byte = f2.read(1)
if (not current_byte):
break
val = ord(current_byte)
q = hex(val)
print q
我不知道下一步是什么你能帮我吗?
【问题讨论】:
标签: python arrays powershell byte shortcut