+ Post New Thread
Results 1 to 8 of 8
Scripts Thread, Script to delete all network printers at logoff? in Coding and Web Development; Anyone know of simple script to delete all Network printers (not local ones) at logoff. We run a script to ...
  1. #1
    woody's Avatar
    Join Date
    Jun 2005
    Location
    Carlisle, Cumbria
    Posts
    617
    Thank Post
    3
    Thanked 17 Times in 15 Posts
    Rep Power
    22

    Script to delete all network printers at logoff?

    Anyone know of simple script to delete all Network printers (not local ones) at logoff. We run a script to add a printer based on machine name but when we occasionally swap a printer in a room and update the script, the old printer driver is left over and these can build up over time.

    Thanks

  2. #2
    Guest

    Re: Script to delete all network printers at logoff?

    Paste the following into notepad:

    Option Explicit
    Dim DelPrint, UNCpath
    UNCpath = "\\%SERVER%\%PRINTER%"
    On Error Resume next
    Set DelPrint = WScript.CreateObject("WScript.Network")
    DelPrint.RemovePrinterConnection UNCpath, true, true
    WScript.Quit

    Change the UNCpath to point to your printer.

    Save it as a .vbs file and volia

  3. #3
    woody's Avatar
    Join Date
    Jun 2005
    Location
    Carlisle, Cumbria
    Posts
    617
    Thank Post
    3
    Thanked 17 Times in 15 Posts
    Rep Power
    22

    Re: Script to delete all network printers at logoff?

    Thanks, I will try this later today!

  4. #4

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,803
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Script to delete all network printers at logoff?

    You might want to look at Ric's printer script. He has a while loop at the start of it to delete all the network printers.

    http://www.edugeek.net/index.php?nam...iewtopic&t=404

  5. #5
    DMcCoy's Avatar
    Join Date
    Oct 2005
    Location
    Isle of Wight
    Posts
    3,432
    Thank Post
    10
    Thanked 488 Times in 428 Posts
    Rep Power
    111

    Re: Script to delete all network printers at logoff?

    This is based on the portname from the print server. It removes all printers that end in .local and .school. Not sure if it works, I've taken it from a bigger script

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set WS_PRINTERS = WshNetwork.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WS_PRINTERS.Count - 1 Step 2
    IF Lcase(right(WS_PRINTERS.Item(LOOP_COUNTER),6)) = "school" THEN
    WshNetwork.removeprinterconnection WS_PRINTERS(LOOP_COUNTER+1), true
    End If
    IF Lcase(right(WS_PRINTERS.Item(LOOP_COUNTER),5)) = "local" THEN
    WshNetwork.removeprinterconnection WS_PRINTERS(LOOP_COUNTER+1), true
    End If
    Next
    Set WS_PRINTERS = Nothing

  6. #6

    Join Date
    Aug 2005
    Location
    Birmingham, UK
    Posts
    490
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Script to delete all network printers at logoff?

    you could just cheat and use con2prt and run:

    Code:
    \\Server\Share\Con2Prt.exe /F
    This will remove all network (but not local) printers

    (yes i know its an NT4 tool, but it works perfectly here and does not require big VBS scripts, why reinvent the wheel?)

  7. #7

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,803
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Script to delete all network printers at logoff?

    why reinvent the wheel?
    Because Microsoft say so!

  8. #8

    Join Date
    Nov 2005
    Posts
    43
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Script to delete all network printers at logoff?

    Quote Originally Posted by E1uSiV3
    you could just cheat and use con2prt and run:

    Code:
    \\Server\Share\Con2Prt.exe /F
    This will remove all network (but not local) printers

    (yes i know its an NT4 tool, but it works perfectly here and does not require big VBS scripts, why reinvent the wheel?)
    I agree, con2prt works great for me, and adprintX is even better, i dont have a preference...

    www.henrymellish.com/adprintx.zip


    sorry DMccoy, advertising again.. I work for Microsoft :P

SHARE:
+ Post New Thread

Similar Threads

  1. Script to delete profile at log off?
    By woody in forum Windows
    Replies: 74
    Last Post: 15th February 2013, 02:28 PM
  2. need a script to delete shortcuts
    By philtomo-25 in forum Scripts
    Replies: 2
    Last Post: 1st November 2007, 03:50 PM
  3. Delete Profile on LogOff
    By roland in forum How do you do....it?
    Replies: 11
    Last Post: 20th September 2007, 09:43 PM
  4. delete printers
    By Jonny_sims in forum Scripts
    Replies: 11
    Last Post: 14th June 2007, 02:54 PM
  5. Script to delete printer
    By tosca925 in forum Scripts
    Replies: 2
    Last Post: 31st August 2005, 07:45 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
  •