MSFN Forum: In need of Printer remove script - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

In need of Printer remove script HELP!! Rate Topic: -----

#1 User is offline   jeremyotten 

  • Junior
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 22-March 05

Posted 26 April 2005 - 09:49 AM

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 ;-)


#2 User is offline   Martin Zugec 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,373
  • Joined: 24-January 04

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 User is offline   jeremyotten 

  • Junior
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 22-March 05

Posted 27 April 2005 - 06:11 AM

No it gave me pop-ups with all the printer names

But not even 1 was removed!

:-(

#4 User is offline   Martin Zugec 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,373
  • Joined: 24-January 04

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 User is offline   jeremyotten 

  • Junior
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 22-March 05

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 User is offline   Martin Zugec 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,373
  • Joined: 24-January 04

Posted 27 April 2005 - 07:05 AM

In that case look here:
http://www.tek-tips....qs.cfm?fid=5798

#7 User is offline   jeremyotten 

  • Junior
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 22-March 05

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..... :-(

#8 User is offline   jeremyotten 

  • Junior
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 22-March 05

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 User is offline   jeremyotten 

  • Junior
  • Pip
  • Group: Members
  • Posts: 62
  • Joined: 22-March 05

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!

@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 User is offline   go4num1alwys 

  • Group: Members
  • Posts: 1
  • Joined: 22-September 05

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 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

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
Martin you seem to be its biggest advocate here will the above do it?

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy