2013-04-26 138 views
1

我試圖修改UAC的權限與PowerShell腳本工作時像:拒絕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

爲什麼它不會運行,即使我運行的腳本作爲管理員的腳本任何想法?還有什麼我需要改變?

+2

我想你想只是'-Verb runAs' - 沒有'Administrator' – 2013-04-26 16:47:59

+0

如果你想的是一個答案,我給你點。 – Thomas 2013-04-27 16:43:35

回答

2

-Verb參數只需要一個變元,例如, print。在海拔的情況下,這將是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對象的動詞性質。