Good Morning! This is my code to remove all printers - please be carefull to stop and start your print spooler. It will remove all printers so please be careful. Add "if" statements if needed to remove only certain printers. UNIVERSAL '****************************************************************
'* SiX 04/09/09 - Remove All Printers *
'*--------------------------------------------------------------*
'* *
'* This script will remove all of your printers!!! *
'* *
'* I highly recommend you stop your print spooler service *
'* by using the "net stop spooler" command. I have not *
'* included this as I intended this script for a startup *
'* or shutdown script and not for just running in general use *
'* *
'* If you use "net stop spooler" then remember to restart *
'* the print spooler service with "net start spooler" after. *
'* *
'**************************************************************** strComputer = "." Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set ColInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer") Set WSHNetwork = wScript.CreateObject("wScript.Network") set Printers = WSHNetwork.EnumPrinterConnections On Error Resume Next 'Registry Entries Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003 ' Object used to get StdRegProv Namespace
Set wmiLocator = CreateObject("WbemScripting.SWbemLocator") ' Object used to determine local machine name
Set wshNetwork = CreateObject("WScript.Network") ' Registry Provider (StdRegProv) lives in root\default namespace. Set wmiNameSpace = wmiLocator.ConnectServer(wshNetwork.ComputerName, "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv") sPath = "Printers\Connections" lRC = DeleteRegEntryUser(HKEY_CURRENT_USER, sPath) sPath = "SYSTEM\CurrentControlSet\Control\Print\Connections" lRC = DeleteRegEntryMachine(HKEY_LOCAL_MACHINE, sPath) Function DeleteRegEntryUser(sHive, sEnumPath) '============================== ' Subkey Enumerator
On Error Resume Next lRC = objRegistry.EnumKey(HKEY_CURRENT_USER, sEnumPath, sNames) For Each sKeyName In sNames lRC = objRegistry.DeleteKey(sHive, sEnumPath & "\" & sKeyName) Next End Function '=============================================================== '########################################################################### Function DeleteRegEntryMachine(sHive, sEnumPath) '=========================== ' Subkey Enumerator
On Error Resume Next lRC = objRegistry.EnumKey(HKEY_LOCAL_MACHINE, sEnumPath, sNames) For Each sKeyName In sNames lRC = objRegistry.DeleteKey(sHive, sEnumPath & "\" & sKeyName) Next End Function '=============================================================== 'Network Machines For IntCount = 0 to Printers.Count - 1 Step 2 WSHNetwork.RemovePrinterConnection Printers.Item(IntCount) Next 'Local Machines For Each objPrinter in ColInstalledPrinters objprinter.delete_ Next WITH IF STATEMENTS FOR MY NETWORK SPECIFICALLY!!!!!!!!!!! 'LCD 23/09/09 - Remove Server Printers
'-------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set ColInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
Set WSHNetwork = wScript.CreateObject("wScript.Network")
set Printers = WSHNetwork.EnumPrinterConnections
'We loop through each printer on the local machine and delete it only
'if the name of the printer starts with "
file://wpbc-p/" (ie it is a print server
'printer)
On Error Resume Next
'Registry Entries
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
' Object used to get StdRegProv Namespace
Set wmiLocator = CreateObject("WbemScripting.SWbemLocator")
' Object used to determine local machine name
Set wshNetwork = CreateObject("WScript.Network")
' Registry Provider (StdRegProv) lives in root\default namespace.
Set wmiNameSpace = wmiLocator.ConnectServer(wshNetwork.ComputerName, "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv")
sPath = "Printers\Connections"
lRC = DeleteRegEntryUser(HKEY_CURRENT_USER, sPath)
sPath = "SYSTEM\CurrentControlSet\Control\Print\Connections"
lRC = DeleteRegEntryMachine(HKEY_LOCAL_MACHINE, sPath)
Function DeleteRegEntryUser(sHive, sEnumPath)
'=======================================
' Subkey Enumerator
On Error Resume Next
lRC = objRegistry.EnumKey(HKEY_CURRENT_USER, sEnumPath, sNames)
For Each sKeyName In sNames
'REMOVE ONLY THE WPBC-PRINT01 AND 02!!!!
if left(sKeyName, 14) = ",,WPBC-PRINT01" or left(sKeyName, 14) = ",,WPBC-PRINT02" then
lRC = objRegistry.DeleteKey(sHive, sEnumPath & "\" & sKeyName)
end if
Next
End Function
'=========================================================================
'##################################################################
Function DeleteRegEntryMachine(sHive, sEnumPath)
'=====================================
' Subkey Enumerator
On Error Resume Next
lRC = objRegistry.EnumKey(HKEY_LOCAL_MACHINE, sEnumPath, sNames)
For Each sKeyName In sNames
'REMOVE ONLY THE WPBC-PRINT01 AND 02!!!!
if left(sKeyName, 14) = ",,WPBC-PRINT01" or left(sKeyName, 14) = ",,WPBC-PRINT02" then
lRC = objRegistry.DeleteKey(sHive, sEnumPath & "\" & sKeyName)
end if
Next
End Function
'=========================================================================
'Network Machines
For IntCount = 0 to Printers.Count - 1 Step 2
if ucase(Left(Printers.item(IntCount + 1), 8)) = "
file://wpbc-p/" then
WSHNetwork.RemovePrinterConnection Printers.Item(IntCount)
end if
Next
'Local Machines
For Each objPrinter in ColInstalledPrinters
tempstring = trim(objprinter.name)
TempString = left(tempstring, 8)
TempString = ucase(tempstring)
if tempstring = "
file://wpbc-p/" then
objprinter.delete_
end if
tempstring = trim(objprinter.name)
TempString = left(tempstring, 2)
TempString = ucase(tempstring)
if tempstring = "1-" then
objprinter.delete_
end if
if tempstring = "0-" then
objprinter.delete_
end if
if tempstring = "2-" then
objprinter.delete_
end if
if tempstring = "3-" then
objprinter.delete_
end if
Next