jeremyotten Posted April 26, 2005 Share Posted April 26, 2005 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 ;-) Link to comment Share on other sites More sharing options...
Martin Zugec Posted April 26, 2005 Share Posted April 26, 2005 Try this (not sure, if it will work for local)On error resume nextSet WshNetwork = WScript.CreateObject("WScript.Network")Set oDrives = WshNetwork.EnumNetworkDrivesSet oPrinters = WshNetwork.EnumPrinterConnectionsFor i = 0 to oDrives.Count - 1 Step 2WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,trueNextFor i = 0 to oPrinters.Count - 1 Step 2WScript.Echo oPrinters.Item(i+1)WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)Next Link to comment Share on other sites More sharing options...
jeremyotten Posted April 27, 2005 Author Share Posted April 27, 2005 No it gave me pop-ups with all the printer namesBut not even 1 was removed!:-( Link to comment Share on other sites More sharing options...
Martin Zugec Posted April 27, 2005 Share Posted April 27, 2005 Strange, here it is working quite well... What cscript version do you have? I use 5.6 Link to comment Share on other sites More sharing options...
jeremyotten Posted April 27, 2005 Author Share Posted April 27, 2005 All of my printers are local printers with TCP/IP mappings to the network printers. Maybe that is the issue? Link to comment Share on other sites More sharing options...
Martin Zugec Posted April 27, 2005 Share Posted April 27, 2005 In that case look here:http://www.tek-tips.com/faqs.cfm?fid=5798 Link to comment Share on other sites More sharing options...
jeremyotten Posted April 27, 2005 Author Share Posted April 27, 2005 Well im a newbie in VBscripting I created this:Dim WSHNetworkSet WSHNetwork = CreateObject("WScript.Network")Set WSHPrinters = WSHNetwork.EnumPrinterConnectionsFor LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,TrueNextbut nothing happend..... :-( Link to comment Share on other sites More sharing options...
jeremyotten Posted April 27, 2005 Author Share Posted April 27, 2005 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) Link to comment Share on other sites More sharing options...
jeremyotten Posted April 27, 2005 Author Share Posted April 27, 2005 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!@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 Link to comment Share on other sites More sharing options...
go4num1alwys Posted September 22, 2005 Share Posted September 22, 2005 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. Link to comment Share on other sites More sharing options...
Yzöwl Posted September 22, 2005 Share Posted September 22, 2005 What about WMIC?Delete Non-Local Printers:wmic printer where "Local='FALSE'" delete>nul 2>&1Delete only Local Printers:wmic printer where "Local='TRUE'" delete>nul 2>&1Delete all Printers:wmic printer delete>nul 2>&1Martin you seem to be its biggest advocate here will the above do it? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now