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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you remove a mapped drive with VBS script? 3

Status
Not open for further replies.

Digitalcandy

IS-IT--Management
May 15, 2003
230
US
Currently I'm using the following to disconnect map drives;

WSHNetwork.RemoveNetworkDrive "G:"

But all this does is "disconnect" the user from "G:" The user can still go into "My Computer", see the disconnected drive, double click it to go right in. Also, when the computer is restarted, "G:" will still be in "My Computer", but show as "disconnected" still allowing the user to access it.

How do you completely remove all traces of it showing in "My Computer" so you don't see it in there?
 
the net use command. Shell out and run that

from a command prompt window type "net use /?" for all the switch settings

_______
I love small animals, especially with a good brown gravy....
 
Digitalcandy,

I've been trying to determine why that doesn't work myself for a long time.... as I see it, the only way that really works is:

wshshell.run "cmd /c net use g: /d /y",1,true

or if you want to wipe all Network Connections, this:

wshshell.run "cmd /c net use * /d /y",1,true

-SWarrior
 
When running the script a command screen opens for a split second. Is there a way to make this script run silent, no popup command window?
 
Either:
wshshell.run "cmd /c net use g: /d /y",2,true
Or:
wshshell.run "cmd /c net use g: /d /y",0,true

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Both commands get rid of my mapped drive, but the CMD window still pops up for a split second. I don't want it to show at all if possible.
 
Hello Digitalcandy!

To keep the window from popping up, simply change the true to a false like this...
Code:
wshshell.run "cmd /c net use g: /d /y",0,false

Good luck!

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
So why the heck are we using the shell and dos commands to begin with? Switch over to a vbscript.

Code:
Dim WSHNetwork
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.RemoveNetworkDrive "G:", True, True

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
snortmare wrote:
>To keep the window from popping up, simply change the true to a false like this...
>CODE
>[tt]wshshell.run "cmd /c net use g: /d /y",0,[blue]false[/blue][/tt]
It is not so. It is the second (0) which does that. The third is related to synchronization. That is what PHV had advised.
- tsuji
 
markdmac,

Dayam !!!
Where did you uncover that info ?? Every documentation of the RemoveDrive that I've found never offered the ,True,True!! Kudo's to YOU MAN!!

-SWarrior
 
You can also map a network drive using the Network object:

Dim WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive G:, "\\server\folder"
WshNetwork.RemoveNetworkDrive G:

A computer always does what you tell it to, but rarely does what you want it to.....
 
SWarrior, one of my favority sites is They have some really helpful examples and a very good search engine. browsing the site is also very intuitive.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
markdmac, thanks for the VBscript way of doing it. This question came about because I'm using your LoginScript.vbs code, and the remove mapped drives portion of the code doesn't have the "True, True" statements in it.

Thanks.
 
Glad to be of service. Enjoy.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top