我正在尝试使用如下所示的 powershell 脚本修改 UAC 的权限:
Start-Process powershell -Verb runAs Administrator
Set-ItemProperty -Path registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -Value 0
$UAC = Get-ItemProperty -Path registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA
$UAC.EnableLUA
即使我以管理员身份运行脚本,我仍然收到以下错误:
Set-ItemProperty : Requested registry access is not allowed. At C:\Users\Bert\Desktop\autoLims.ps1:8 char:17 + Set-ItemProperty <<<< -Path registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -Value 0 + CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...policies\system:String) [Set-ItemProperty], SecurityException + FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.SetItemPropertyCommand
有什么想法为什么即使我以管理员身份运行脚本它也不会运行脚本吗?我还需要改变什么吗?
最佳答案
-Verb
参数仅接受一个参数,例如打印
。在提升的情况下,它将是 RunAs
,它将以当前用户的完全权限运行该进程。
来自Start-Process documentation :
-Verb <String>
指定启动进程时要使用的动词。可用的动词由进程中运行的文件的文件扩展名决定。
下表显示了一些常见进程文件类型的动词。
File type Verbs
--------- -------
.cmd Edit, Open, Print, Runas
.exe Open, RunAs
.txt Open, Print, PrintTo
.wav Open, Play
要查找可与进程中运行的文件一起使用的动词,请使用 New-Object
cmdlet 创建一个 System.Diagnostics.ProcessStartInfo
对象文件。可用的动词位于 ProcessStartInfo
对象的 Verbs 属性中。
关于windows - 修改UAC时Powershell管理员权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16239994/