Posts Tagged ‘Windows 7’

Turn Off the UAC with Powershell

I wrote this script to turn off the UAC on our HPC R2 grid with 64 servers.  It works very well, but there is not any real error handling in there to account for offline computers.  If you are doing this for Windows 7 computers that may or may not be online, you may want to add some custom ping checks to keep the script from blowing chunks.

As always, uses the script in whole or in part, but I’d appreciate some props if you do.

########################################################################
#
#	Disable User Account Control
#
#	Author:  Jim Melton
#
#	This script checks the registry for all computer in a flat file
#		and checks to see if the UAC is turned on.  If it is, it will
#		set the EnableLUA value to 0.  The script can be modified to
#		enable the UAC if need be.  A machine reboot is required to
#		complete the change.
#
########################################################################
 
########################################################################
#
#	Initialize variables and set paths
#
########################################################################
$computers = Get-Content ""
$WriteUAC = $true
$UACvalue = "EnableLUA"
$UACoff   = 0
$UACpath  = "Software\Microsoft\Windows\CurrentVersion\policies\system"
 
########################################################################
#
#	Loop through the input file for all computers, open the remote
#		HKLM hive using .NET, open the subkey to the UAC setting, and
#		get the Enable UAC value.
#
########################################################################
ForEach($computer in $computers){
 
  $OpenRegistry = [Microsoft.Win32.RegistryKey]::`
	OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$computer)
 
  $UACsubkey = $OpenRegistry.OpenSubKey($UACpath,$WriteUAC)
  $UACsubkey.ToString()
  $UACstate  = $UACsubkey.GetValue($UACvalue)
  Write-Host "The UAC on $computer is currently set to $UACstate."
 
########################################################################
#
#	If the EnableLUA value is set to 1, set it to 0.  Grab the EnableLUA
#		value after the change to make sure it was successful.
#
########################################################################
 
  If($UACstate -eq 1)
    {
	Write-Host "Turning the UAC off..."
	$UACsubkey.SetValue($UACvalue, $UACoff)
	$UACstate = $UACsubkey.GetValue($UACvalue)
	Write-Host "The UAC on $computer is now set to $UACstate.`
             The computer needs to be rebooted."
    }
}