如何使用Windows PowerShell禁用UAC?

10

如何使用PowerShell脚本禁用UAC?我可以通过添加以下注册表项手动完成此操作。

Key:   HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
Value: 0
Type:  DWORD
该脚本应考虑到该键可能已经存在且设置不正确的情况。
2个回答

17
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
Restart-Computer

更改生效需要进行重启吗? - Eddie Studer
我在Windows 10上成功测试了这个行为,它在Windows 7上也能工作吗?不幸的是,我没有Win 7客户端进行自己的测试。问候 Alexander - Alexander Powolozki

1

1 - 将以下两个函数添加到您的PowerShell配置文件(C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1)中

2 - 在PowerShell中运行Disable-UAC

3 - 重新启动计算机以使更改生效。使用PowerShell,可以执行Restart-Computer -Force -Confirm:$false

Function Test-RegistryValue 
{
    param(
        [Alias("RegistryPath")]
        [Parameter(Position = 0)]
        [String]$Path
        ,
        [Alias("KeyName")]
        [Parameter(Position = 1)]
        [String]$Name
    )

    process 
    {
        if (Test-Path $Path) 
        {
            $Key = Get-Item -LiteralPath $Path
            if ($Key.GetValue($Name, $null) -ne $null)
            {
                if ($PassThru)
                {
                    Get-ItemProperty $Path $Name
                }       
                else
                {
                    $true
                }
            }
            else
            {
                $false
            }
        }
        else
        {
            $false
        }
    }
}

Function Disable-UAC
{
    $EnableUACRegistryPath = "REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System"
    $EnableUACRegistryKeyName = "EnableLUA"
    $UACKeyExists = Test-RegistryValue -RegistryPath $EnableUACRegistryPath -KeyName $EnableUACRegistryKeyName 
    if ($UACKeyExists)
    {
        Set-ItemProperty -Path $EnableUACRegistryPath -Name $EnableUACRegistryKeyName -Value 0
    }
    else
    {
        New-ItemProperty -Path $EnableUACRegistryPath -Name $EnableUACRegistryKeyName -Value 0 -PropertyType "DWord"
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接