renamed hkey scripts
This commit is contained in:
4
RemoveHKeyPrinters.cmd
Normal file
4
RemoveHKeyPrinters.cmd
Normal file
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
REM Ensure PowerShell execution regardless of local policy
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "\\domain_name\SYSVOL\domain_name\scripts\Printers\RemoveHKeyPrinters.ps1"
|
||||
exit /b %ERRORLEVEL%
|
||||
51
RemoveHKeyPrinters.ps1
Normal file
51
RemoveHKeyPrinters.ps1
Normal file
@@ -0,0 +1,51 @@
|
||||
$profileListKey = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
|
||||
|
||||
$sids = Get-ChildItem $profileListKey
|
||||
|
||||
$printerPaths = @(
|
||||
'\Printers\Connections',
|
||||
'\Printers\ConvertUserDevModesCount',
|
||||
'\Software\Xerox\PrinterDriver',
|
||||
'\Software\Microsoft\Windows NT\CurrentVersion\Devices'
|
||||
)
|
||||
|
||||
$HKLMPrinterPaths = @(
|
||||
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers',
|
||||
'HKEY_LOCAL_MACHINE\SOFTWARE\Xerox\PrinterDriver'
|
||||
)
|
||||
|
||||
net stop spooler
|
||||
|
||||
foreach ($printerPath in $HKLMPrinterPaths) {
|
||||
try {
|
||||
Remove-Item -Path "Registry::$printerPath" -Recurse -Force -ErrorAction Stop
|
||||
} catch {
|
||||
Write-Host "Error: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($sidKey in $sids) {
|
||||
$sid = $sidKey.PSChildName
|
||||
$profilePath = (Get-ItemProperty -Path $sidKey.PSPath -Name ProfileImagePath).ProfileImagePath
|
||||
|
||||
|
||||
|
||||
foreach ($printerPath in $printerPaths) {
|
||||
try {
|
||||
Remove-Item -Path "Registry::HKEY_USERS\$sid$printerPath" -Recurse -Force -ErrorAction Stop
|
||||
} catch {
|
||||
Write-Host "Error: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (-not $mounted) {
|
||||
$unloadResult = & reg.exe unload "HKU\$sid" 2>&1
|
||||
}
|
||||
}
|
||||
|
||||
net start spooler
|
||||
|
||||
gpupdate /force
|
||||
|
||||
New-Item -Path "C:\ProgramData\PrinterHKeyClean\v1.flag" -ItemType File -Force
|
||||
Reference in New Issue
Block a user