Configure a user’s taskbar position and autohidden status. The user must not be logged in locally. (Edited to properly close handle to registry)
# Script to autohide taskbar on account dictated below. User account must exist first. Param( [string]$username = $(throw "-username is required."), [string]$password, [string]$domain = $(throw '-domain is required ("local" for local accounts).'), [bool]$hide = $true, [int]$position = 3 ) # Wrap reg edits in function to ensure no handles left on the registry Function SafetyReg { # Hardcode hex key, if no HKCU key exists to use as a template. $HardcodeW7 = "28,00,00,00,ff,ff,ff,ff,03,00,00,00,03,00,00,00,3e,00,00,00,28,00,00,00,00,00,00,00,d8,02,00,00,00,04,00,00,00,03,00,00" # $HardcodeW8 = "28,00,00,00,ff,ff,ff,ff,03,02,00,00,03,00,00,00,3e,00,00,00,28,00,00,00,00,00,00,00,d8,02,00,00,00,04,00,00,00,03,00,00" $HardcodeW10 = "30,00,00,00,fe,ff,ff,ff,03,02,00,00,03,00,00,00,7c,00,00,00,28,00,00,00,00,00,00,00,10,04,00,00,80,07,00,00,38,04,00,00,60,00,00,00,01,00,00,00" If (Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2) { $stuckrects = "StuckRects2" $Hardcode = $HardcodeW7 } Else { $stuckrects = "StuckRects3" $Hardcode = $HardcodeW10 } # Need to manually close handles to registry keys created by New-Item cmdlet $handle1 = New-Item -Path "HKLM:\Temp\Software\Microsoft\Windows\CurrentVersion\Explorer" -Name $StuckRects –Force $keyuser = "HKLM:\Temp\Software\Microsoft\Windows\CurrentVersion\Explorer\$StuckRects" $keytemplate = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\$StuckRects" $data = (Get-ItemProperty -Path $keytemplate -Name Settings).Settings if ($data -eq $null) { $hex = $hardcode.Split(',') | % { "0x$_"} If ($hide) { $hex[8] = 3 } Else { $hex[8] = 2 } $hex[12] = $position New-ItemProperty -Path $keyuser -Name Settings -PropertyType Binary -Value ([byte[]]$hex) -Force } else { If ($hide) { $data[8] = 3 } Else { $data[8] = 2 } $data[12] = $position Set-ItemProperty -Path $keyuser -Name Settings -Value $data } # Garbage collection maintenance $handle1.Handle.Close() [gc]::collect() } If([String]::IsNullOrEmpty($password)) { $secpassword = New-Object System.Security.SecureString } Else { $secpassword = $password | ConvertTo-SecureString -AsPlainText -Force } if ($domain -eq "local") {$domain = $env:COMPUTERNAME} # Details and credentials with which to run a new process $startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo.FileName = "cmd.exe" $startInfo.WorkingDirectory = "$($env:windir)\system32\" $startInfo.RedirectStandardOutput = $true $startInfo.UseShellExecute = $false $startInfo.CreateNoWindow = $false $startInfo.Username = $username $startInfo.Password = $secpassword $startInfo.Domain = $domain $startInfo.LoadUserProfile = $true # Run the new process as the user, ensuring the user's hive file is created $process = New-Object System.Diagnostics.Process $process.StartInfo = $startInfo $proc = $process.Start() Stop-Process $process.Id -Force # User hive file $ntuserlocation = "$env:Systemdrive\users\" + $username + "\ntuser.dat" reg load 'HKLM\Temp' $ntuserlocation SafetyReg reg unload HKLM\Temp