+ Post New Thread
Results 1 to 9 of 9
Windows Thread, Deleting networked printer via logon script in Technical; I have tried to use the following script to delete our old printer from our client machines: Code: start \SERVER\ICT_HP4050N ...
  1. #1

    Join Date
    May 2006
    Posts
    1,315
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Deleting networked printer via logon script

    I have tried to use the following script to delete our old printer from our client machines:

    Code:
    start \\SERVER\ICT_HP4050N
    
    rundll32 printui.dll,PrintUIEntry /gd /n\\SERVER\ICT_HP4050N N
    When I run it though, it comes up with the following error:

    Unable to delete the per machine printer connection. Operation could not be completed
    Does anyone know why this is happening? Google doesn't give me any info. The printer was added using a similar script, so it should work.

    Cheers!

  2. #2

    Join Date
    Jun 2007
    Location
    Leicestershire
    Posts
    82
    Thank Post
    24
    Thanked 3 Times in 2 Posts
    Rep Power
    15

    Re: Deleting networked printer via logon script

    I dunno why that doesn't work, but I use the following within a vbs to it (assuming you added the printer with the network name, which in your case it looks like it did (\\SERVER):

    Code:
      Option Explicit
    
      On Error Resume Next
    
      Dim objNetwork
      Dim objPrinters, ix
      Set objNetwork = CreateObject("WScript.Network")
      Set objPrinters = objNetwork.EnumPrinterConnections
    
      ' ### Delete all currently installed network printers
      For ix= 0 to objPrinters.Count - 1 Step 2
       Dim sPrinter, sUNCPath
       sPrinter = objPrinters.Item(ix)
       sUNCPath = objPrinters.Item(ix+1)
    
       If InStr(1, sPrinter, "NAME_OF_SERVER", 1) > 0 Then
        objNetwork.RemovePrinterConnection sPrinter, True, True
       ElseIf InStr(1, sUNCPath, "NAME_OF_SERVER", 1) > 0 Then
        objNetwork.RemovePrinterConnection sUNCPath, True, True
       End If
    
       If Err <> 0 Then
        Wscript.Echo "Error deleting printer: " & Err.Description
        Err.Clear
       End If
      Next

  3. Thanks to lovelldr from:

    MrLudwig (2nd March 2009)

  4. #3

    Join Date
    May 2006
    Posts
    1,315
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Deleting networked printer via logon script

    That deletes all the network printers? I can only delete the one. We have more then one installed on each machine.

  5. #4

    Join Date
    Jun 2007
    Location
    Leicestershire
    Posts
    82
    Thank Post
    24
    Thanked 3 Times in 2 Posts
    Rep Power
    15

    Re: Deleting networked printer via logon script

    OK, something like this should do it then:

    Code:
      Option Explicit
    
      Dim objNetwork, objPrinters
      Set objNetwork = CreateObject("WScript.Network")
      Set objPrinters = objNetwork.EnumPrinterConnections
    
      ' ### Delete selected network printer
      Dim sPrinterName
      sPrinterName = "\\SERVER\ICT_HP4050N"
      objNetwork.RemovePrinterConnection sPrinterName, True, True

  6. #5

    Join Date
    May 2006
    Posts
    1,315
    Thank Post
    101
    Thanked 25 Times in 18 Posts
    Rep Power
    25

    Re: Deleting networked printer via logon script

    Thanks very much! That worked!

  7. #6

    Join Date
    Jun 2007
    Location
    Leicestershire
    Posts
    82
    Thank Post
    24
    Thanked 3 Times in 2 Posts
    Rep Power
    15

    Re: Deleting networked printer via logon script

    np

  8. #7

    Join Date
    Sep 2008
    Location
    Leicester
    Posts
    24
    Thank Post
    3
    Thanked 2 Times in 1 Post
    Rep Power
    12
    Hi, is it possible to remove a printer that has been added using
    START \\CHSDC\CR1-COLOUR
    within a batch file that runs at start up.

  9. #8

    Join Date
    Jun 2007
    Location
    London
    Posts
    894
    Thank Post
    64
    Thanked 171 Times in 140 Posts
    Rep Power
    55
    If you use KiXtart you could use

    DelPrinterConnection("\\SERVER\ICT_HP4050N")

  10. #9

    Join Date
    Sep 2008
    Location
    Leicester
    Posts
    24
    Thank Post
    3
    Thanked 2 Times in 1 Post
    Rep Power
    12
    thanks timzim

    i've also found

    reg delete "hkcu\printers\connections" /f

    works nicely in a batch file

SHARE:
+ Post New Thread

Similar Threads

  1. logon script for printer
    By ozzy in forum Scripts
    Replies: 6
    Last Post: 22nd November 2007, 03:03 PM
  2. Logon script & Printer script question.
    By Galway in forum Windows
    Replies: 3
    Last Post: 29th August 2007, 11:00 AM
  3. BGInfo in logon script example?
    By ninjabeaver in forum How do you do....it?
    Replies: 16
    Last Post: 24th August 2007, 12:49 PM
  4. Networked OKI Printer Problem
    By markesmith in forum Wireless Networks
    Replies: 4
    Last Post: 20th February 2007, 12:23 AM
  5. Yet another Logon Script
    By ajbritton in forum Windows
    Replies: 3
    Last Post: 19th June 2006, 09:47 AM

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
  •