remove printer hkey
This commit is contained in:
31
RemoveHKLMPrinters.ps1
Normal file
31
RemoveHKLMPrinters.ps1
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
$profileListKey = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
|
||||||
|
|
||||||
|
$sids = Get-ChildItem $profileListKey |
|
||||||
|
Where-Object { $_.PSChildName -match '^S-1-5-21-\d+-\d+-\d+-\d+$' }
|
||||||
|
|
||||||
|
foreach ($sidKey in $sids) {
|
||||||
|
$sid = $sidKey.PSChildName
|
||||||
|
$profilePath = (Get-ItemProperty -Path $sidKey.PSPath -Name ProfileImagePath).ProfileImagePath
|
||||||
|
|
||||||
|
if (-not $profilePath) { continue }
|
||||||
|
|
||||||
|
$ntUserDat = Join-Path $profilePath 'NTUSER.DAT'
|
||||||
|
if (-not (Test-Path $ntUserDat)) { continue }
|
||||||
|
|
||||||
|
$mounted = $false
|
||||||
|
try {
|
||||||
|
if (Test-Path "Registry::HKEY_USERS\$sid") { $mounted = $true }
|
||||||
|
} catch { $mounted = $false }
|
||||||
|
|
||||||
|
if (-not $mounted) {
|
||||||
|
$loadResult = & reg.exe load "HKU\$sid" "$ntUserDat" 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Remove-Item -Path "Registry::HKEY_USERS\$sid\Printers" -Recurse -Force -ErrorAction Stop
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
if (-not $mounted) {
|
||||||
|
$unloadResult = & reg.exe unload "HKU\$sid" 2>&1
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user