Delete Printer via Group Policy

qwertyiopqwertyiop Member Posts: 725 ■■■□□□□□□□
We are replacing one of our office copiers and I would like to add a line to our logon script that delete the printer at logon.

I'm currently using the following line but it doesnt seem to be working:

Net Use Canonirc / Delete

Comments

  • qwertyiopqwertyiop Member Posts: 725 ■■■□□□□□□□
    I endedup using the following instead but I still have one more problem.

    rundll32 printui.dll,PrintUIEntry /dn /n \\server\printername


    I dont want it to run if the printer doesnt exist. I would like to use the IF EXISTS command but first I need a way to see if the printer is actually installed. Do any of you have any ideas?
  • Hyper-MeHyper-Me Banned Posts: 2,059
    Do you guys not make use of Group Policy Preferences CSEs?

    I dont know what id do without them.
  • qwertyiopqwertyiop Member Posts: 725 ■■■□□□□□□□
    Hyper-Me wrote: »
    Do you guys not make use of Group Policy Preferences CSEs?

    I dont know what id do without them.


    I never heard of it
  • NightShade03NightShade03 Member Posts: 1,383 ■■■■■■■□□□
    You can use the following as part of a logon script policy.

    NOTE: This wasn't tested so please use with caution (although it should work no problem) icon_wink.gif
    On Error Resume Next
    
    ' This script will be run against the local computer
    strComputer = "."
    
    ' The next two set commands will query all the printers on the local computer
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set colInstalledPrinters =  objWMIService.ExecQuery _
        ("Select * from Win32_Printer")
        
    ' Iterate through the printers found
    For Each objPrinter in colInstalledPrinters
        ' Uncomment for some debugging (the printer's name)
        'Wscript.Echo "Name: " & objPrinter.Name
        
        If objPrinter.Name == "Name_of_old_printer" Then
            objPrinter.Delete_
        End If
    Next
        
    ' Once old printer is gone add the new one
    
    Set WshNetwork = CreateObject("WScript.Network")
    
    ' Uncomment the second line if you want to set the new printer as the default
    
    WshNetwork.AddWindowsPrinterConnection "\\PrintServer1\Name_of_new_printer"
    'WshNetwork.SetDefaultPrinter "\\PrintServer1\Name_of_new_printer"
    
    Wscript.Quit
    
    
  • rwwest7rwwest7 Member Posts: 300
    Group Policy Preference Client Side Extensions Available

    You need a Vista computer in order to apply them, but they can be applied to XP and above as long as an update is installed.
Sign In or Register to comment.