Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RemovePrinterConnection fails on Windows 2000

Status
Not open for further replies.

stev379

Technical User
Jan 2, 2005
19
US
We're migrating printers from 1 server to 2 new servers. All HP goes to one server now and non HP to another. The script works great on Windows XP. But on Windows 2000 it adds the new printers pointed to the new servers correctly, but fails to delete the old printers. I've tried tried using a script to remove 1 printer from a 2000 box and it fails saying it can't find the connection.

'This fails on W2K but works fine on XP.
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\OLDSERVER\HP12-3017"


Any clues as to why this happens or suggestions on how to remove a printer with VBS from a W2K machines would be great!!

Thanks for any help!
-Steve
 
Are you sure the 2000 box has the latest scripting runtime (5.6) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Just installed it, rebooted and tested again. Same result.

"The network connection does not exist."

I've tried enumerating and echoing to test and get a list of the printers.
I then enumerating on a box with only 1 printer installed and used that enumeration as a variable to remove and got the same result on W2K.
 
is this the sum of your code???

'This fails on W2K but works fine on XP.
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\OLDSERVER\HP12-3017"

 
documentation said:
object.RemovePrinterConnection(strName, [bForce], [bUpdateProfile])

Remarks
The RemovePrinterConnection method removes both Windows and MS-DOS based printer connections. If the printer was connected using the method AddPrinterConnection, strName must be the printer's local name. If the printer was connected using the AddWindowsPrinterConnection method or was added manually (using the Add Printer wizard), then strName must be the printer's UNC name.
Check out the remarks?
 
Thanks all!

To answer mrmovie, no that's not the sum of the script, the full script is 390 lines, so I just posted the trouble part. But I did test with a script that contained only the snippet I posted and got the same errors.

tsuji, I found the same article tried modify the script or tried different scripts all together and got the same errors.

SOLUTION:
I added an if statement to check the OS and if it's W2K run this (on one line of course):

sDel2KPrts = "rundll32printui.dll,PrintUIEntry /q /dn /n " & sPrinterName




Thanks for the help and suggestions!!

 
Thanks stev379 for the feedback. I think that touches upon some complication on this matter which is that there is a systematic apart involving rundll32..., namely, with running the dll:
[tt] rundll32 printui.dll,PrintUIEntry [options] [@commandline][/tt]

[1] Printer connections
For those printer connections which are added by the line with the option [blue]/ga[/blue] should be removed by the same with [blue]/gd[/blue].
[2] Network printer connections
For those added by the option [blue]/in[/blue] should be removed by the same with the switch [blue]/dn[/blue].

That is a systematic apart.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top