Link to home
Create AccountLog in
Avatar of bpl5000

asked on

Disconnecting a UNC connection

Does anyone know how to find and delete a UNC connection to a server?  I want an automated way to find a UNC connection to a specific server and then delete it. When it's a UNC path, it does not seem to be stored anyplace.

For example, if you run the following command:
net use \\server\share password /u:username

it will attach you to the share.  You can run netstat on the command line and see that you have a connection to the server, but it does not give the share name.  Does anyone know how to determine what connections to a share on a specific server exist and how to remove the connection?  I would like to put this into a VB program when I determine how to accomplish this.  Please NO LINKS!  I want someone who knows how to do this, not someone who will just google the topic and paste links.
Avatar of Member_2_2473503
Flag of Philippines image

You can use net use /delete to delete the maped path

Avatar of Michael Pfister
net use

without parameters will list all mapped connections to shares, with or without drive letter.

net use \\UNC-Path /delete /y

will disconnect the share.

net use * /del /y

will disconnect all shares.

Hope it helps.
Avatar of bpl5000


mpfister, you gave me what I was asking, but I can't incorporate it into a VB program the way I'd like to.  I would like to disconnect all connections to the server  If I launch

net use \\ /delete /y

It does not work.  If I include the share name, then it does work.  If I use "net use * /del /y", then it would get rid of all other server connections that might be needed.

I wish I could do something like...
net use \\\* /del /y

Is there any way to delete all connections to a server without knowing the name of the share and without deleting all other server connections?
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
You need to modify line 16 , insert your server name instead of the IP.
Avatar of bpl5000


mpfister, you are a genius!  All I need to do is convert this from VBS to VB code and I will have just what I need.

Thanks for your help!
Avatar of bpl5000


Put this code into my VB6 program and it works perfect!  Thanks again for the help!
Avatar of bpl5000


Thank you SO MUCH for this code!  It works perfect!
Glad it helped!