+ Post New Thread
Results 1 to 12 of 12
Scripts Thread, delete printers in Coding and Web Development; hi all, Here's the situation. We are moving away from a localy managed tcp/ip printers to a central print server, ...
  1. #1
    Jonny_sims's Avatar
    Join Date
    Oct 2006
    Location
    darlington
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    delete printers

    hi all,

    Here's the situation. We are moving away from a localy managed tcp/ip printers to a central print server, for printer usage monitoring.

    I have used ric's script to add the networked printers to the computers at startup, but i want to save a bit of time and have it delete printers on tcp/ip ports, but keep printers on other ports. this is because we use cutepdf and we have a printer setup to print directly to reprographics, i also dont want to interfere with any printers that staff have setup on there laptops for home use.

    So to sumerise i need some help with a vbscript to delete all printers on tcp/ip ports only.

    Thanks for your help

  2. #2

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,678
    Thank Post
    661
    Thanked 1,626 Times in 1,455 Posts
    Rep Power
    422

    Re: delete printers

    set wNet = createobject("wscript.network")
    'Remove ALL old printers
    'Enumerate all printers first, after that you can select the printers you want by performing some string checks
    Set WSHPrinters = WNet.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    'To remove only networked printers use this If Statement
    If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
    WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    End If
    'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
    'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    Next
    'end delete existing printers


    Ben

  3. #3
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: delete printers

    Which script are you using again.. doesnt ric's script only removed network printers anyway?

  4. #4
    Jonny_sims's Avatar
    Join Date
    Oct 2006
    Location
    darlington
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: delete printers

    ric's script only removes network printers which are on a print server. i have network printers that go directly to the printer from the computer.

  5. #5

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,678
    Thank Post
    661
    Thanked 1,626 Times in 1,455 Posts
    Rep Power
    422

    Re: delete printers

    Ok do you know the port names for the ones you want to delete?

    Ben

  6. #6
    Jonny_sims's Avatar
    Join Date
    Oct 2006
    Location
    darlington
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: delete printers

    the port names should be "IP_ip of the printer"

    which is just the standard that windows setsup.

  7. #7
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: delete printers

    Odd, just had a quick look and it looks like ric's script removes anything except those that have "usb" or "lpt" in the port name. Maybe im looking at the wrong script but all you need to do is to edit plexer script or add to it.
    Code:
    'To remove only networked printers use this If Statement
    If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
    WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    End If
    This bit of code defines what to remove by using the port name ie it searches for "\\" so all you have to do is to copy the whole thing and change that value with something like "IP". Think thats about right (correct me if im wrong).

  8. #8
    Jonny_sims's Avatar
    Join Date
    Oct 2006
    Location
    darlington
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: delete printers

    i have tried the script, it runs through without errors but does not delete the printers.

  9. #9
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: delete printers

    Right ok i think ive posted up a script to deal with your problem.. whats going on is that you have printers that are locally installed on you machines (right?) and the script wont get rid of it, which it souldnt do cause it tries to delete the network printer. There is a script to do it but it doesnt always work and you will need to reghack it to get rid. Here is the script to get rid of 1 local printer:

    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set colInstalledPrinters =  objWMIService.ExecQuery ("Select * from Win32_Printer where DeviceID = 'HP LaserJet 1100")
    
    For Each objPrinter in colInstalledPrinters
        objPrinter.Delete_
    Next
    Ill sort out another script to get rid of locally installed network printers in a bit.

  10. #10
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: delete printers

    Ok heres a script to delete more than multiple printers.

    Code:
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    'Remove All Network Printers.
    
    Set oPrinters = WshNetwork.EnumPrinterConnections
    FOR Counter = 0 to oPrinters.Count - 1
    	IF mid(oPrinters.Item(Counter), 1, 2) = "IP" THEN
    		PrinterPath = oPrinters.Item(Counter + 1)
    		Set colInstalledPrinters =  objWMIService.ExecQuery ("Select * from Win32_Printer where DeviceID = '" & PrinterPath & "'")
    		For Each Printer in colInstalledPrinters
        			Printer.Delete_
    		Next		
    	End If
    Next

  11. #11
    Jonny_sims's Avatar
    Join Date
    Oct 2006
    Location
    darlington
    Posts
    35
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: delete printers

    thanks for all your help. It has saved be about a weeks work going round manully deleting printer

  12. #12
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: delete printers

    No Probs.. I assume it worked then

SHARE:
+ Post New Thread

Similar Threads

  1. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 13
    Last Post: 22nd February 2013, 03:53 PM
  2. Script to delete profile at log off?
    By woody in forum Windows
    Replies: 74
    Last Post: 15th February 2013, 02:28 PM
  3. faster way to delete
    By mac_shinobi in forum Scripts
    Replies: 4
    Last Post: 14th December 2007, 08:51 AM
  4. Replies: 7
    Last Post: 27th November 2005, 10:41 PM

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
  •