windows - 修改UAC时Powershell管理员权限被拒绝

标签 windows powershell windows-7-x64

我正在尝试使用如下所示的 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/

相关文章:

c - 如何在函数中返回字符串数组?

wpf - 带上下文菜单的 Out-GridView

opencl - 如何使用 Qt Creator 编译一个简单的 OpenCL 应用程序?

windows - 以编程方式检测 Windows 上是否启用了 VT-x 或 AMD-v

c++ - Windows 最接近 fork() 的是什么?

powershell - Powershell : How to check the good execution of a batch file on a remote computer using invoke-command

powershell - 如何使用包含数组或列表的 JSON Body 执行 webrequest?

python - %USERPROFILE% python 环境变量

java - Tomcat 中的 HttpServletRequest.getRemoteAddr() 返回 IPv6 格式的 IP 地址

c - SIGSEGV,Windows 中的段错误,但在 Linux 中运行良好