+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
Scripts Thread, Removing printers in Coding and Web Development; Ok, I need a script that will remove all printers from a workstation, EXCEPT where that printer is connected via ...
  1. #1

    Join Date
    Jun 2005
    Location
    Elgin, Scotland
    Posts
    387
    Thank Post
    1
    Thanked 4 Times in 4 Posts
    Rep Power
    23

    Removing printers

    Ok, I need a script that will remove all printers from a workstation, EXCEPT where that printer is connected via LPT or USB.

    Basically, all of our network printers are connected directly to the network and so are installed on the PC as Local printers using a Standard TCP/IP Port. I now need to remove them as I need to do a bulk update of drivers and printer types (so many changes!). I've tried variations of the scripts I've found on here, but none seem to actually work. Anyone know how to do what I'm after?

    And no, I can't run them all through a server or use logon scripts (don't you just love managed services!).

    Cheers all,

    Rob Cowan.

  2. #2
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,987
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    107

    Re: Removing printers

    I will assume you have looked ar Rics script.
    I think with your setup its this line that needs changing

    Code:
    For i = 0 to oPrinters.Count - 1 Step 2
    Its something to do with the step that handles those direct printers because when I log onto the print server my log in script does not delete all the printers. Try it without the step 2 or look at con2prt.

  3. #3

    Join Date
    Nov 2005
    Location
    North Tyneside LEA
    Posts
    34
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: Removing printers

    Why not just disconnect all printers and then reconnect the relevant ones depending on the computer and its location? Might make things easier in the long run.

    Rob.

  4. #4
    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: Removing printers

    Try this:

    Code:
    on error resume next
    Set shell= WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    dim Counter, PrinterPath
    
    'Remove All Network Printers.
    
    Set oPrinters = WshNetwork.EnumPrinterConnections
    FOR Counter = 0 to oPrinters.Count - 1
    	IF mid(oPrinters.Item(Counter), 1, 2) = "\\" THEN
    		PrinterPath = oPrinters.Item(Counter)
    		WshNetwork.RemovePrinterConnection PrinterPath, True, True
    	End If
    Next

  5. #5

    Join Date
    Jun 2005
    Location
    Elgin, Scotland
    Posts
    387
    Thank Post
    1
    Thanked 4 Times in 4 Posts
    Rep Power
    23

    Re: Removing printers

    Ok. I've found a solution of sorts. I'm now using the Prnmngr.vbs script that appears to come with Windows XP.

    @Chris: Cheers for the pointer. I might look down that route if I ever get more time/vbscript skills.

    @_Rob_: Was trying to avoid this but I think it's going to have to be the way.

    @apeo: Unfortunately, I've already tried that script. I'm not 100% sure, but I think it's actually looking for the beginnings of a UNC path in the printer settings, which these won't have as they're running direct to an IP address.

    Either way, thanks for the responses. And if anyone's interested in it, you can find out more about Prnmngr.vbs here

  6. #6
    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: Removing printers

    Oh right you have printers installed locally using IP. Yes your are right is is looking for the first 2 chars of unc path so in your case i probably would have deleted all printers that ltp: or usb: ie if not ltp: then but as you have alredy foud a way it doesnt really matter

  7. #7

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 769 Times in 598 Posts
    Rep Power
    181

    Re: Removing printers

    I think you'll find that the script at http://edugeek.net/index.php?name=Fo...iewtopic&t=404 does this for you

  8. #8
    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: Removing printers

    Man what was up with my last post.. loads of typos ops:

    @Ric_: Yup, the section on your script that deletes printers did what i suggested.

  9. #9

    Join Date
    Jun 2005
    Location
    Elgin, Scotland
    Posts
    387
    Thank Post
    1
    Thanked 4 Times in 4 Posts
    Rep Power
    23

    Re: Removing printers

    @Ric: Nope, tried that one too. It's entirely possible that these PCs are just doing this to annoy me. Also, I'm not running the script as a logon script. It's actually being punted out using the Ghost Console which then executes the command on each system locally (or that's the theory anyway!). I would love to use it as a logon script, but I have no control over those.

  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: Removing printers

    Just checked it out and i think its case sensitive so lpt should be LPT. Oh thanks for letting us know about the Prnmngr.vbs, may come it handy at some point in the future.

  11. #11
    fooby's Avatar
    Join Date
    Dec 2005
    Posts
    351
    Thank Post
    0
    Thanked 5 Times in 4 Posts
    Rep Power
    19

    Re: Removing printers

    con2prt /f

    Deletes all connections to network printers, leaves local ones alone. works for us here.

    http://www.ss64.com/nt/con2prt.html

  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: Removing printers

    Problem is, it is a local printer but uses ip for port so con2prt wont work.

  13. #13
    fooby's Avatar
    Join Date
    Dec 2005
    Posts
    351
    Thank Post
    0
    Thanked 5 Times in 4 Posts
    Rep Power
    19

    Re: Removing printers

    Ah right I see. You are right, con2prt will ignore that then.

  14. #14

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 769 Times in 598 Posts
    Rep Power
    181

    Re: Removing printers

    What context does your script get run as? Logon scripts run with elevated priviledges and if that doesn't work, run it as a startup script cos then it will run as SYSTEM.

  15. #15
    ajbritton's Avatar
    Join Date
    Jul 2005
    Location
    Wandsworth
    Posts
    1,632
    Thank Post
    23
    Thanked 75 Times in 45 Posts
    Rep Power
    34

    Re: Removing printers

    Quote Originally Posted by Ric_
    Logon scripts run with elevated priviledges...
    Really? I thought they ran in the user security context. Is there any MS documentation on that?

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Removing Ranger
    By alan-d in forum Windows
    Replies: 17
    Last Post: 7th September 2009, 02:09 PM
  2. Removing the view Menu
    By faza in forum Wireless Networks
    Replies: 3
    Last Post: 11th October 2007, 07:56 AM
  3. Removing a GPO
    By _Bat_ in forum Windows
    Replies: 12
    Last Post: 3rd May 2007, 04:27 PM
  4. Removing Linux from my PDA
    By dezt in forum *nix
    Replies: 7
    Last Post: 21st September 2006, 01:54 PM
  5. Removing Profiles on a Server
    By wesleyw in forum How do you do....it?
    Replies: 2
    Last Post: 22nd August 2006, 10:01 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
  •