+ Post New Thread
Results 1 to 7 of 7
Windows Thread, Removing old server printers in Technical; Having changed our print server recently we still have a number of printers 'on old servername' showing up to staff. ...
  1. #1
    bondbill2k2's Avatar
    Join Date
    Jan 2011
    Location
    West Midlands
    Posts
    1,015
    Thank Post
    81
    Thanked 66 Times in 51 Posts
    Blog Entries
    2
    Rep Power
    42

    Removing old server printers

    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

    Code:
    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?

  2. #2
    RichCowell's Avatar
    Join Date
    Dec 2005
    Location
    PR7, Lancashire
    Posts
    482
    Thank Post
    84
    Thanked 81 Times in 68 Posts
    Rep Power
    32
    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...

    Code:
    ' 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...

  3. Thanks to RichCowell from:

    bondbill2k2 (16th May 2012)

  4. #3
    Mcshammer_dj's Avatar
    Join Date
    Feb 2007
    Location
    Portsmouth
    Posts
    971
    Thank Post
    38
    Thanked 174 Times in 139 Posts
    Rep Power
    96
    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
    Last edited by Mcshammer_dj; 15th May 2012 at 05:06 PM.

  5. #4
    RichCowell's Avatar
    Join Date
    Dec 2005
    Location
    PR7, Lancashire
    Posts
    482
    Thank Post
    84
    Thanked 81 Times in 68 Posts
    Rep Power
    32
    Quote Originally Posted by Mcshammer_dj View Post
    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

  6. #5
    Mcshammer_dj's Avatar
    Join Date
    Feb 2007
    Location
    Portsmouth
    Posts
    971
    Thank Post
    38
    Thanked 174 Times in 139 Posts
    Rep Power
    96
    yeah I am trying to find my other script

    reg delete "hkcu\printers\connections" /f
    Last edited by Mcshammer_dj; 15th May 2012 at 05:09 PM.

  7. #6


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,818
    Thank Post
    231
    Thanked 890 Times in 765 Posts
    Rep Power
    302
    best way ive found to remove printers is gpp

  8. #7
    bondbill2k2's Avatar
    Join Date
    Jan 2011
    Location
    West Midlands
    Posts
    1,015
    Thank Post
    81
    Thanked 66 Times in 51 Posts
    Blog Entries
    2
    Rep Power
    42
    Quote Originally Posted by RichCowell View Post
    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...

    Code:
    ' 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
    Last edited by bondbill2k2; 16th May 2012 at 10:26 AM.

  9. Thanks to bondbill2k2 from:

    icesalim (5th October 2012)



SHARE:
+ Post New Thread

Similar Threads

  1. Removing Old Server References
    By soveryapt in forum Windows Server 2000/2003
    Replies: 4
    Last Post: 20th November 2009, 10:49 AM
  2. Laptop still loading Printer on old server
    By Jon-Dukes in forum Windows
    Replies: 7
    Last Post: 8th June 2009, 02:28 PM
  3. DFS/FRS error with removing an old server
    By FatBoy in forum Windows
    Replies: 2
    Last Post: 23rd October 2008, 11:05 AM
  4. Replies: 7
    Last Post: 31st December 2007, 09:16 PM
  5. Replies: 7
    Last Post: 16th December 2007, 01:56 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •