+ Post New Thread
Results 1 to 8 of 8
Scripts Thread, Remove Old Printers in Coding and Web Development; I have a very simple script to remove all network printers, however this does not remove old printers that are ...
  1. #1

    Join Date
    Mar 2010
    Location
    Hampshire
    Posts
    39
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Remove Old Printers

    I have a very simple script to remove all network printers, however this does not remove old printers that are no longer attached to the network.

    How should I modify the attached script to remove 'all' printers?

    Go easy on me, scripts are not my forte
    Attached Files Attached Files

  2. #2

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,817
    Thank Post
    1,624
    Thanked 1,880 Times in 1,397 Posts
    Blog Entries
    2
    Rep Power
    426
    I've used this in the past to remove network printers

    Code:
    'Remove all Network printers but not local printers
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set Printers = WshNetwork.EnumPrinterConnections
    
    For i = 0 to Printers.Count - 1 Step 2
    
        If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
            WScript.Echo Printers.Item(i+1)
            WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
        End IF
    Next
    and this to remove local printers

    Code:
    'Remove all Local printers but not Network printers
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    Set colInstalledPrinters =  objWMIService.ExecQuery _
        ("Select * from Win32_Printer Where Network = FALSE")
    
    For Each objPrinter in colInstalledPrinters
        objPrinter.Delete_
    Next

  3. #3

    Join Date
    Mar 2010
    Location
    Hampshire
    Posts
    39
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for the reply.

    Whilst this does remove network printers, it does not seem to remove printers that are dead i.e status is "unable to connect"

    Any other ideas?

  4. #4

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,817
    Thank Post
    1,624
    Thanked 1,880 Times in 1,397 Posts
    Blog Entries
    2
    Rep Power
    426
    sorry, I missed that, this will do it.

    Code:
    'Remove all offline printers
    set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
    
    set sInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer where ExtendedPrinterStatus = 7")
    
    For Each sPrinter in sInstalledPrinters
     sPrinter.Delete_
    Next

  5. #5

    Join Date
    Mar 2010
    Location
    Hampshire
    Posts
    39
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    That didn't work either i'm afraid. Printers remain and doesn't return any form of error.

  6. #6

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,817
    Thank Post
    1,624
    Thanked 1,880 Times in 1,397 Posts
    Blog Entries
    2
    Rep Power
    426
    hmmm...that should detect all offline printers and remove them, networked or local...in that case, I am not sure where you can proceed from here.

  7. #7

    Ephelyon's Avatar
    Join Date
    Aug 2008
    Location
    Cheshire, England
    Posts
    1,658
    Thank Post
    287
    Thanked 318 Times in 192 Posts
    Rep Power
    141
    Could see if "con2prt /f" helps.

  8. #8

    Join Date
    Mar 2010
    Location
    Hampshire
    Posts
    39
    Thank Post
    6
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for your suggestions. Looks like reg delete "hkcu\printers\connections" /f will work.

SHARE:
+ Post New Thread

Similar Threads

  1. Removing old server printers
    By bondbill2k2 in forum Windows
    Replies: 6
    Last Post: 16th May 2012, 09:18 AM
  2. Replies: 11
    Last Post: 20th November 2009, 01:07 PM
  3. Removing old flash player from Macromedia Studio MX
    By randle in forum Educational Software
    Replies: 6
    Last Post: 13th August 2009, 01:50 PM
  4. Remove PDF Printers
    By EduTech in forum How do you do....it?
    Replies: 3
    Last Post: 22nd September 2008, 02:00 PM
  5. [MS Office - 2003] deleting old printers.
    By MrPstv in forum Office Software
    Replies: 5
    Last Post: 10th September 2008, 10:50 AM

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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