Chr*_*nce 10 registry powershell uac
如何使用PowerShell脚本禁用UAC?我可以使用添加以下注册表项通过注册表手动执行此操作
Key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA
Value: 0
Type: DWORD
Run Code Online (Sandbox Code Playgroud)
该脚本应考虑到此密钥已存在且设置不正确的可能性.
Dav*_*ant 18
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
Restart-Computer
Run Code Online (Sandbox Code Playgroud)
1 - 将以下两个函数添加到您的 PowerShell 配置文件中 ( C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1)
2 -Disable-UAC在 PowerShell 中运行
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"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30628 次 |
| 最近记录: |