No announcement yet.

Delete the Printers using script

  • Filter
  • Time
  • Show
Clear All
new posts

  • Delete the Printers using script

    Hi All,

    I am a new member of this group, let me say Hi to all...

    I would like to know, how can i delete the printers which i installed through a Vbs script,
    We have more than 14 networked printers and using the vbs script we installed printers on all the computers, now the boss want me to remove all other printers except the printer where the user sits to avoid the wastage of paper, i cant go and remove printers from all the PCs, so would like to know how can i remove using a script,

    Now i am giving a dedicated printer for users in their particular area using the start up script ..


    I was using this vbs script ( which i got from a forum) to install, and i am not good in vbs scripts..

    Set wshNetwork = CreateObject("WScript.Network")
    wshNetwork.AddwindowsPrinterConnection "\\servername\printername"

    Can i anyone help me? now i denied permission from the printer security settings for the users, but i have few roaming users who has got permision on multiple printers, so can i use any script on the PC group, rather than giving it for user group?

    I am using windows 2003 server, win xp clients, and we are using the script on the GPO ( logon script)

    Last edited by techlearner; 20th October 2009, 09:03.

  • #2
    Re: Delete the Printers using script

    Am i doing something wrong to post the message?


    • #3
      Re: Delete the Printers using script

      Off the top of my head it should be

      Set wshNetwork = CreateObject("WScript.Network")
      wshNetwork.RemoveWindowsPrinterConnection "\\servername\printername"


      • #4
        Re: Delete the Printers using script

        Originally posted by techlearner View Post
        Am i doing something wrong to post the message?
        Not sure, have you checked the eventlogs?

        Looking for a vbs or batch solution?
        If you google for AddwindowsPrinterConnection I'm sure you'll find also samples where RemovePrinterConnection is used to remove the printer mappings. So what is exactly the question?, and what have you tried so far?

        For samples and remarks about removing printers by using a vbs user-logon-script you can also search Petri's scripting forum:

        Batch using Rundll32.exe printui.dll,PrintUIEntry (case sensitive):

        Batch ( *.cmd or *.bat file) using the WSH RemovePrinterConnection method:
        :: Run this BATCH ( *.bat file) as part of the User Logon Script !
        :: ** Remove all connected Network Printers
        @echo off & cls
        Goto:endVBS-1 *** begin of vbscript 1 ***
        'Delete all printers 'VBS-1
        Set WshNetwork = WScript.CreateObject("WScript.Network") 'VBS-1
        With WshNetwork.EnumPrinterConnections 'VBS-1
           For i = 0 to .Count - 1 Step 2 'VBS-1
             If Left(ucase(.Item(i+1)),2) = "\\" Then 'VBS-1
               WshNetwork.RemovePrinterConnection  .Item(i+1) 'VBS-1
             End IF 'VBS-1
           Next 'VBS-1
           wscript.echo "network printers removed" 'VBS-1
        End With 'VBS-1
        :endVBS-1 *** end of vbscript 1 ***
        :: Remove Printers
           Set "VBS#=VBS-1"
           Set "wrkFile=%temp%.\$$$%VBS#%$$$"
           Findstr.exe /ic:"'%VBS#%" "%~0" >"%wrkFile%"
           Cscript.exe /E:vbscript /Nologo "%wrkFile%"
        endlocal & Del "%wrkFile%"

        If you like to un-install a printerdriver from the computer, use a computer-startup-script, see:

        Last edited by Rems; 20th October 2009, 14:46.

        This posting is provided "AS IS" with no warranties, and confers no rights.


        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts


        • #5
          Re: Delete the Printers using script

          Thank you for the Reply,

          I am looking to delete those printers which is there on every PCs which was installed through the VBs script which i mentioned, now i want to remove all printers from PCs,

          For this VB script to work should all the users must have the rights on printers? as i removed printing rights from all the printers for eveyone group, and i am giving only those printers where they sit, This is my question.. i wish my question is clear

          Now next query is, i want to create a batch file for PC group ( a OU consists of PCs ) where onlly the printer which is sitting there should be installed, and i think i am using the correct batch file.. which also i mentioned below


          Can u guide me?


          Tech Learner


          • #6
            Re: Delete the Printers using script

            hi all,
            i solved the issue, thanks for the support

            I created a batch file for removing and adding the printers and copied into the startup of each computer

            Thanks again