Skip to content

Instantly share code, notes, and snippets.

@ferventcoder
Created December 4, 2013 19:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferventcoder/7793999 to your computer and use it in GitHub Desktop.
Save ferventcoder/7793999 to your computer and use it in GitHub Desktop.
UAC Handling
$uacRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
$uacRegValue = "EnableLUA"
$uacEnabled = $false
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
$osVersion = [Environment]::OSVersion.Version
if ($osVersion -ge [Version]'6.0')
{
$uacRegSetting = Get-ItemProperty -Path $uacRegPath
try {
$uacValue = $uacRegSetting.EnableLUA
if ($uacValue -eq 1) {
$uacEnabled = $true
}
} catch {}
}
if ($uacEnabled) {
Set-ItemProperty -Path $uacRegPath -Name $uacRegValue -Value 0
}
# stuff here
if ($uacEnabled) {
Set-ItemProperty -Path $uacRegPath -Name $uacRegValue -Value 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment