Jump to content

Recommended Posts

Posted

Having changed our print server recently we still have a number of printers 'on old servername' showing up to staff. Im trying to clear these off with a script but having issues. I have tried using con2prnt /f which only removes the current servers printers not the no longer existing ones and a script I found on here

 

Option Explicit

 On Error Resume Next

 Dim objNetwork
 Dim objPrinters, ix
 Set objNetwork = CreateObject("WScript.Network")
 Set objPrinters = objNetwork.EnumPrinterConnections

 ' ### Delete all currently installed network printers
 For ix= 0 to objPrinters.Count - 1 Step 2
  Dim sPrinter, sUNCPath
  sPrinter = objPrinters.Item(ix)
  sUNCPath = objPrinters.Item(ix+1)

  If InStr(1, sPrinter, "SERVERNAME", 1) > 0 Then
   objNetwork.RemovePrinterConnection sPrinter, True, True
  ElseIf InStr(1, sUNCPath, "SERVERNAME", 1) > 0 Then
   objNetwork.RemovePrinterConnection sUNCPath, True, True
  End If

  If Err <> 0 Then
   Wscript.Echo "Error deleting printer: " & Err.Description
   Err.Clear
  End If
 Next

 

Which shows the error when ran on clients and profiles and mandatory.

All clients are windows XP btw. Im guessing they can't kill the connection to a none existent server?

Posted

I use the following, seems to have worked well with XP and Win 7 as it's been running on login for years and I'd forgotten about it until I saw your post...

 

' don't display any error messages
On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
   ("Select * From Win32_Printer Where Network = True")

For Each objPrinter in colInstalledPrinters
   objPrinter.Delete_
Next

 

I should add - that removes all network printers, so it's set to run before the add printers script...

  • Thanks 1
Posted (edited)

if you are using scripting then I assume that you are using a sript to map the new printers?

 

use a batch file to remove all printers

Edited by Mcshammer_dj
Posted
if you are using scripting then I assume that you are using a sript to map the new printers?

 

if so then this may help??

 

I could have sworn that's what I just said :-p

Posted (edited)
I use the following, seems to have worked well with XP and Win 7 as it's been running on login for years and I'd forgotten about it until I saw your post...

 

' don't display any error messages
On Error Resume Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
   ("Select * From Win32_Printer Where Network = True")

For Each objPrinter in colInstalledPrinters
   objPrinter.Delete_
Next

 

I should add - that removes all network printers, so it's set to run before the add printers script...

 

Works great just tryed it as a local admin account and manually running it. I will add it to the computers shutdown scripts to clear at power off, printers are mapped at user logon so it should avoid any problems and clear that backlog of old printers and staff shouldn't see a longer logon or power on time

Edited by bondbill2k2
  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...