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

Disconnect network drives on logoff 1

Status
Not open for further replies.

JacksonGuy

IS-IT--Management
Dec 18, 2003
38
US
Hello,
I am new to vbscripts and I am trying to write a script that scans for attached network drives and deletes them on logoff. I am trying to put the script in vbs at the domain level in GPO. I ahve tried a number of different things and none of them have been successful. Your help would be appreciated.
 
can i ask a question?
what benefits can the approach of disconnecting network drives have? im interested. i spent 3 months writting to a "unified logon script" which i think is the absolute dogs nuts and the thought of a logoff script never even entered my head!!! ;-)

regards
von moyla
 
Something like this ?
Set WN=CreateObject("WScript.Network")
Set ND=WNetwork.EnumNetworkDrives
For i=ND.Count-1 To 0 Step -2
WN.RemoveNetworkDrive ND.Item(i),True
Next

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
mrmovie well there are a number of reasons the number one is that when a drive sticks if the drive path is changed for one reason or another it don't work properly. Another reason is that if somone was to manually map a drive and forget to disconnect it it is stuck on the machines. Another one is that we just started doing logon scripts through GPO and the vbs script throws an error whenever it encounters a drive that is stuck, this has been resolved by "on error next"

 
PHV,
I tried that script and I got an error. Line 2 Char 1
Object Required "WNetwork"

Sorry I am so stupid on this topic I am by no means a programer.

Thanks for your help

 
Sorry for the typo:
Set WN=CreateObject("WScript.Network")
Set ND=WN.EnumNetworkDrives
For i=ND.Count-1 To 0 Step -2
WN.RemoveNetworkDrive ND.Item(i),True
Next

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV
I got past that line and now I get Ln4 Char 3
The Network Connection does not exist
 
You must have some connections without mapped drive.
Try this:
Set WN=CreateObject("WScript.Network")
Set ND=WN.EnumNetworkDrives
On Error Resume Next
For i=ND.Count-1 To 0 Step -2
WN.RemoveNetworkDrive ND.Item(i),True
Next

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Are the drive letters static? If so, just throw a simple cmd line at them via the RUN method of "net use X: /DELETE" at them where X is the drive letter.
 
PHV
It don't throw the error anymore however it don't do anything. It just kinda stops executing. We do have a floppy, hard drive, and cd rom drive.

Narizza28,
I have tried NET USE * /delete /Yes and it does work however it takes a long time to run the script.
 
Try this:
Set WN=CreateObject("WScript.Network")
Set ND=WN.EnumNetworkDrives
On Error Resume Next
For i=ND.Count-[highlight]2[/highlight] To 0 Step -2
WN.RemoveNetworkDrive ND.Item(i),True
Next

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
it is still not working I am starting to wounder if it is one of those things that cannot be done. Instead is there a way that anyone knows of to turn persistent off in vbs? Maybe that is the way that I need to look at this.

Thanks
 
Hello JacksonGuy,

Make sure, by say .echo ND.item(2n) even items see if they are lettered as expect. If they are letter-less, applies the RemoveNetworkDrive on the odd items instead.

regards - tsuji
 
After siting here thinking about it it does work if I just launch it however, when I put into GPO to run as a logoff script then it does not work. So I am beginning to think that it is a Microsoft thing and not a scripting thing. Correct me If I am wrong.
 
tsuji,
I'm sorry I don't understand what you are trying to say. Where do I put what where?
 
tsuji, I gave the 2 approaches: the UNC one and the mapped letter drive one.
I don't understand why it's not working for JacksonGuy.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
ok after the last post I now feel real stupid here. I tried it on another machine and discovered that it is the machine that I am using. The one that I am having problems with has A-G physical drives. The ones that have a,c,d works fine. Sorry about that I guess I should of covered all my grounds first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top