如何使用PowerShell脚本禁用UAC?我可以通过添加以下注册表项手动完成此操作。
Key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
Value: 0
Type: DWORD
该脚本应考虑到该键可能已经存在且设置不正确的情况。如何使用PowerShell脚本禁用UAC?我可以通过添加以下注册表项手动完成此操作。
Key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
Value: 0
Type: DWORD
该脚本应考虑到该键可能已经存在且设置不正确的情况。New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
Restart-Computer
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"
}
}