No announcement yet.

Remove Network printers from all profiles

  • Filter
  • Time
  • Show
Clear All
new posts

  • Remove Network printers from all profiles

    Dear colleagues,

    I've tried to find it for a while. I need to delete all network printers from all profiles in a computer.

    I cannot use Rundll32 printui.dll,PrintUIEntry /gd /c\\localcomputername /n\\server\sharename", vbNormalFocus command because they were not added using the printui.dll.

    All scripts I found was to delete printers installed for logged on users only. I need one to check all the profiles in the computer and delete the network printers. I cannot also add it to a log off script because I don't have permission to change GPO.

    Scripts I used to delete network printers for logged on users:

    'Call RemovePrintersFromServer function
    'Function to remove all the printers from a specific server
    sub RemovePrintersFromServer(sServerName)
        dim oPrinters, aPrinter    
        Set oPrinters = objNetwork.EnumPrinterConnections
        For i = 0 to oPrinters.Count - 1 Step 2
            on error resume next
                aPrinter = split(uCase(oPrinters.Item(i+1)),"\",-1, 1)  '"
                if not UBound(aPrinter) = 0 then  'this is not a local printer, process code
                    if aPrinter(2) = ucase(sServerName) then
                        objNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, True                    
                    end if
                end if
            aPrinter = ""
            on error goto 0
    End Sub
    or this one:
    strComputer = "." 
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
    Set colInstalledPrinters =  objWMIService.ExecQuery _ 
        ("Select * from Win32_Printer Where Network = TRUE") 
    For Each objPrinter in colInstalledPrinters 

    Best regards,
    Last edited by biggles77; 6th May 2011, 12:05. Reason: Wrap script with CODE tag

  • #2
    Re: Remove Network printers from all profiles

    Hey just wanted to say thanks for this script, it's exactly what I was looking for since we're going to be pushing out printers using group policy soon. Needed a clean slate.