2012-03-05 38 views
10

Làm cách nào để tắt UAC bằng tập lệnh PowerShell? Tôi có thể thực hiện việc này theo cách thủ công qua đăng ký bằng cách thêm mục đăng ký sauLàm cách nào để tắt UAC bằng Windows PowerShell?

Key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA 
Value: 0 
Type: DWORD 

Tập lệnh nên tính đến khả năng khóa này đã có và đặt không chính xác.

Trả lời

1

1 - Thêm hai chức năng sau đây để hồ sơ của bạn PowerShell (C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1)

2 - Chạy Disable-UAC trong PowerShell

3 - Khởi động lại để thay đổi có hiệu lực. Sử dụng PowerShell, đây sẽ là 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" 
    } 
} 
18
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force 
Restart-Computer 
+0

Liệu khởi động lại đã xảy ra trong trật tự để thay đổi xảy ra? –

+0

Nevermind chỉ trả lời câu hỏi của riêng tôi. –

+0

Tôi đã thử nghiệm hành vi này thành công trên windows 10, nó cũng hoạt động trên các cửa sổ 7? Thật không may tôi đã không giành được 7 khách hàng cho thử nghiệm của riêng mình. Kính trọng Alexander –

Các vấn đề liên quan