PDA

View Full Version : RemovePrinterConnection (W2K)



awistaiw
12-17-2002, 02:19 AM
I have successfully mapped a printer to \\server\printer using a script, and now want to remove it using a script. The RemovePrinterConnection method pops up an error, "This network connection does not exist.", with the source of the error as the method RemoveNetworkDrive(!) Any ideas? I copied the code straight off the tutorial posted on the site, and edited it so it pointed to the printer share.

Here is the code for reference anyway:

Set WshNetwork = WScript.CreateObject("WScript.Network")

'remove a remote mapping
WshNetwork.RemovePrinterConnection "\\link1\HP Upstairs"

Do I perhaps need to make it a local connection rather than a UNC share in the RemovePrinterConnection method's parameters?

Thanks in advance,

Alastair

adamdelves
12-17-2002, 03:10 AM
I notice you have a space in the pinter name. So the RemovePrinterConnection method ma be trying to disconnect "\\link1\HP" instead try the following:
<pre>
Set WshNetwork = WScript.CreateObject("WScript.Network")

'remove a remote mapping
WshNetwork.RemovePrinterConnection """\\link1\HP Upstairs"""
</pre>
This will enclose the string in qutoes to it is "\\link1\HP Upstairs".

Hope this helps,
ADAM

awistaiw
12-17-2002, 11:29 AM
Thanks, I'll give it a go!