使用powershell获取UAC设置
是否有方法使用powershell获取windows 7计算机中的UAC状态(包括级别)使用powershell获取UAC设置,powershell,Powershell,是否有方法使用powershell获取windows 7计算机中的UAC状态(包括级别) (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).EnableLUA 将告诉您UAC是否启用。UAC级别记录在系统注册表项中。您可以使用下面的代码来获取它们 $Key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Sy
(Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).EnableLUA
将告诉您UAC是否启用。UAC级别记录在系统注册表项中。您可以使用下面的代码来获取它们
$Key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
$ConsentPromptBehaviorAdmin_Name = "ConsentPromptBehaviorAdmin"
$PromptOnSecureDesktop_Name = "PromptOnSecureDesktop"
$ConsentPromptBehaviorAdmin_Value = Get-RegistryValue $Key $ConsentPromptBehaviorAdmin_Name
$PromptOnSecureDesktop_Value = Get-RegistryValue $Key $PromptOnSecureDesktop_Name
$PROPERPTBEHAVIORADMIN_值和$PROMPTONSECURE桌面_值之间的不同组合定义了UAC级别
对于完整的示例,您可以参考@ravikanth已经发布了一个很好的答案,但是对于那些探索其他选项的人来说,这里有两种其他方法可以以不同的方式获得相同的信息:
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLUA
或
eric给出的答案很好,但需要声明函数Get RegistryValue。因此,首先您需要:
Function Get-RegistryValue($key, $value) { (Get-ItemProperty $key $value).$value }
然后,您可以获得他描述的设置:
$Key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
$ConsentPromptBehaviorAdmin_Name = "ConsentPromptBehaviorAdmin"
$PromptOnSecureDesktop_Name = "PromptOnSecureDesktop"
$ConsentPromptBehaviorAdmin_Value = Get-RegistryValue $Key $ConsentPromptBehaviorAdmin_Name
$PromptOnSecureDesktop_Value = Get-RegistryValue $Key $PromptOnSecureDesktop_Name
然后,您可以使用以下方法解释这些值:
If($ConsentPromptBehaviorAdmin_Value -Eq 0 -And $PromptOnSecureDesktop_Value -Eq 0){
"Never notIfy"
}
ElseIf($ConsentPromptBehaviorAdmin_Value -Eq 5 -And $PromptOnSecureDesktop_Value -Eq 0){
"NotIfy me only when apps try to make changes to my computer(do not dim my desktop)"
}
ElseIf($ConsentPromptBehaviorAdmin_Value -Eq 5 -And $PromptOnSecureDesktop_Value -Eq 1){
"NotIfy me only when apps try to make changes to my computer(default)"
}
ElseIf($ConsentPromptBehaviorAdmin_Value -Eq 2 -And $PromptOnSecureDesktop_Value -Eq 1){
"Always notIfy"
}
Else{
"Unknown"
}
从。还可以根据需要将其作为布尔值拉出,例如[bool]((Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policys\System).EnableLUA))
If($ConsentPromptBehaviorAdmin_Value -Eq 0 -And $PromptOnSecureDesktop_Value -Eq 0){
"Never notIfy"
}
ElseIf($ConsentPromptBehaviorAdmin_Value -Eq 5 -And $PromptOnSecureDesktop_Value -Eq 0){
"NotIfy me only when apps try to make changes to my computer(do not dim my desktop)"
}
ElseIf($ConsentPromptBehaviorAdmin_Value -Eq 5 -And $PromptOnSecureDesktop_Value -Eq 1){
"NotIfy me only when apps try to make changes to my computer(default)"
}
ElseIf($ConsentPromptBehaviorAdmin_Value -Eq 2 -And $PromptOnSecureDesktop_Value -Eq 1){
"Always notIfy"
}
Else{
"Unknown"
}