Jump to content

Deleting networked printer via logon script


Recommended Posts

Posted

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

 

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!

Posted

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):

 

 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

  • Thanks 1
Posted

OK, something like this should do it then:

 

 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

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...