当我尝试使用 runas 来提升权限时,我发现了一些事情。简单的 Win10 机器,具有已拥有管理员权限的单用户。我需要通过脚本写入特定的注册表项,但当我直接尝试使用 reg 命令时,我收到“访问被拒绝”的消息。
> reg ...
ERROR: Access is denied.
Run Code Online (Sandbox Code Playgroud)
如果我尝试:
> runas /user:Administrator Command
Enter the password for Administrator:
1326: The user name or password is incorrect.
Run Code Online (Sandbox Code Playgroud)
它拒绝我的用户密码。我认为本地计算机上没有特定的管理员密码,对吧?没有其他帐户了。试:
> runas /user:MyUser Command
Enter the password for MyUser:
740: The requested operation requires elevation
Run Code Online (Sandbox Code Playgroud)
那么如何从命令行提升权限?!?为什么我在这里看不到我有管理员权限:
>runas /showtrustlevels
The following trust levels are available on your system:
0x20000 (Basic User)
Run Code Online (Sandbox Code Playgroud)
编辑:也许我应该更清楚我想做什么。我想从 C 程序更改 WT_KEY_HKLM,“Software\Microsoft\Windows\CurrentVersion\Run”。我可以直接在 XP 中执行此操作,但在更新版本的 Windows 中,它没有效果。事实上,从命令行对此键运行“reg”会导致访问被拒绝。我不想以提升的权限运行我的程序,所以我的想法是做类似 system("runas reg ...") 的事情,它会要求输入密码并更改注册表。但我什至无法从命令行获取该命令。也许有人可以建议正确的方法来做到这一点?
小智 5
将 [user] 和 [command] 替换为您要使用的内容并尝试一下:
powershell.exe -ExecutionPolicy Bypass -command "& {Start-Process powershell.exe -Credential '[user]' -ArgumentList 'Start-Process ""[command]"" -Verb runAs'}"
Run Code Online (Sandbox Code Playgroud)
优点:
缺点:
如果您想从 PowerShell 提示符运行此命令,可以将其缩短为:
Start-Process powershell.exe -Credential '[user]' -ArgumentList 'Start-Process ""[command]"" -Verb runAs`'
Run Code Online (Sandbox Code Playgroud)
S。
| 归档时间: |
|
| 查看次数: |
9046 次 |
| 最近记录: |