I'm in need of a script that remove every printer that is installed on my machine. Whether it is a network or a local printer!
after that the script will add the new printer mapping. This last thing is no problem. But I can't seem to be able to make a script that removes every printer without it having to know certain printer names etc.
Maybe someone here is up to the challenge ;-)
Page 1 of 1
In need of Printer remove script HELP!!
#2
Posted 26 April 2005 - 11:50 AM
Try this (not sure, if it will work for local)
On error resume next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oDrives.Count - 1 Step 2
WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
Next
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo oPrinters.Item(i+1)
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)
Next
#3
Posted 27 April 2005 - 06:11 AM
No it gave me pop-ups with all the printer names
But not even 1 was removed!
:-(
But not even 1 was removed!
:-(
#4
Posted 27 April 2005 - 06:22 AM
Strange, here it is working quite well... What cscript version do you have? I use 5.6
#5
Posted 27 April 2005 - 07:01 AM
All of my printers are local printers with TCP/IP mappings to the network printers. Maybe that is the issue?
#6
Posted 27 April 2005 - 07:05 AM
#7
Posted 27 April 2005 - 08:05 AM
Well im a newbie in VBscripting I created this:
Dim WSHNetwork
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next
but nothing happend..... :-(
Dim WSHNetwork
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next
but nothing happend..... :-(
#8
Posted 27 April 2005 - 11:16 AM
I found this cmd script which work perfect for local printers. Maybe someone can change it so that is also will work for network printers.
@Echo Off If Not %1'==/?' Goto Begin Echo Removes Windows NT's printers (Registry-settings and printer driver's files). Echo. Echo %~n0 (Goto :EOF) :Begin (Echo [Version] Echo Signature = "$Windows NT$" Echo. Echo [DefaultInstall] Echo DelReg = DelReg Echo AddReg = AddReg Echo. Echo [DelReg] Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Printers" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2" Echo. Echo [AddReg] Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Printers","DefaultSpoolDirectory",,, Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Printers","DefaultSpoolDirectory",,"%%SystemRoot%%\System32\spool\PRINTERS" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2",,, Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2","Directory",,"2" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2","MajorVersion",%%REG_DWORD%%,2 Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2","MinorVersion",%%REG_DWORD%%,0 Echo. Echo [Strings] Echo REG_SZ = 0x00000000 Echo REG_MULTI_SZ = 0x00010000 Echo REG_EXPAND_SZ = 0x00020000 Echo REG_BINARY = 0x00000001 Echo REG_DWORD = 0x00010001)>%TEMP%.\$%~n0.inf If Not Exist %TEMP%.\$%~n0.inf ( Echo Can not write to: %TEMP%.\$%~n0.inf Goto :EOF) Echo Remove all printers on %COMPUTERNAME% %SystemRoot%\system32\net.exe STOP SPOOLER %SystemRoot%\system32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 128 %TEMP%.\$%~n0.inf Del %TEMP%.\$%~n0.inf For %%F In (%SystemRoot%\system32\spool\drivers\w32x86) Do ( %SystemRoot%\system32\attrib.exe -r -s -h %%F\*.* /S Del /Q /S %%F\*.*) %SystemRoot%\system32\net.exe START SPOOLER (goto :EOF)
#9
Posted 27 April 2005 - 12:07 PM
I changed it myself! NOW it remove all local drivers! All local PRINTERS! All NETWORK Printers! And even All TCP/IP Ports! All nice and clean ;-)
Test it out and give FEEDBACK!
Test it out and give FEEDBACK!
@Echo Off If Not %1'==/?' Goto Begin Echo Removes Windows NT's printers (Registry-settings and printer driver's files). Echo. Echo %~n0 (Goto :EOF) :Begin (Echo [Version] Echo Signature = "$Windows NT$" Echo. Echo [DefaultInstall] Echo DelReg = DelReg Echo AddReg = AddReg Echo. Echo [DelReg] Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Printers" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3" Echo HKCU,"Printers\Connections" Echo HKCU,"Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts" Echo HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\LanMan Print Services\Servers" Echo HKLM,"SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" Echo. Echo [AddReg] Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Printers","DefaultSpoolDirectory",,, Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Printers","DefaultSpoolDirectory",,"%%SystemRoot%%\System32\spool\PRINTERS" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2",,, Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2","Directory",,"2" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2","MajorVersion",%%REG_DWORD%%,2 Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2","MinorVersion",%%REG_DWORD%%,0 Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3",,, Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3","Directory",,"2" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3","MajorVersion",%%REG_DWORD%%,2 Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3","MinorVersion",%%REG_DWORD%%,0 Echo HKCU,"Printers\Connections" Echo HKCU,"Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts" Echo HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\LanMan Print Services\Servers" Echo HKLM,"SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports" Echo HKLM,"SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" Echo. Echo [Strings] Echo REG_SZ = 0x00000000 Echo REG_MULTI_SZ = 0x00010000 Echo REG_EXPAND_SZ = 0x00020000 Echo REG_BINARY = 0x00000001 Echo REG_DWORD = 0x00010001)>%TEMP%.\$%~n0.inf If Not Exist %TEMP%.\$%~n0.inf ( Echo Can not write to: %TEMP%.\$%~n0.inf Goto :EOF) Echo Remove all printers on %COMPUTERNAME% %SystemRoot%\system32\net.exe STOP SPOOLER %SystemRoot%\system32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 128 %TEMP%.\$%~n0.inf Del %TEMP%.\$%~n0.inf For %%F In (%SystemRoot%\system32\spool\drivers\w32x86) Do ( %SystemRoot%\system32\attrib.exe -r -s -h %%F\*.* /S Del /Q /S %%F\*.*) %SystemRoot%\system32\net.exe START SPOOLER
#10
Posted 22 September 2005 - 10:55 AM
My situation is quite opposite. I need a script that will remove all the network printers but it will not alter/remove the local printers. This code deletes all the printers and I want to keep the local printers. I will give you an example to make myself clear. Lets say I have 5 printers (A, B, C, D and E). A, B, and C are Network Printers and D and E are local. I want a script that will remove A,B, and C(including Driver and Ports) but leave D and E on the machine. Please help.
#11
Posted 22 September 2005 - 01:43 PM
What about WMIC?
- Delete Non-Local Printers:
wmic printer where "Local='FALSE'" delete>nul 2>&1
Delete only Local Printers:
wmic printer where "Local='TRUE'" delete>nul 2>&1
Delete all Printers:
wmic printer delete>nul 2>&1
- ← Batch file problems...
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- VBS Script to edit Registry →
Share this topic:
Page 1 of 1



Help
Back to top








