troubleshooting Question

RemoveNetworkDrive leaves drive mapping for user to reconnect

Avatar of OnsiteSupport
OnsiteSupport asked on
Active DirectoryVB Script
2 Comments1 Solution352 ViewsLast Modified:
This seems like a no-brainer, but when I run the script below, I show "Disconnect Network Drive."  But, it allows the user to double click on it thru Explorer and it reconnects.  So, I really need a Disconnect Network Drive that deletes the mapping.

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, objNetwork, objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set oNet = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
UserString = WSHNetwork.UserName
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
Rem *******************************Map based on Group Memberships**********************************
For Each GroupObj In UserObj.Groups
    Select Case GroupObj.Name
        Case "Farmingdale"
           If objFSO.DriveExists("F:")=True Then WSHNetwork.RemoveNetworkDrive"F:"
           If objFSO.DriveExists("M:")=False Then WSHNetwork.MapNetworkDrive "m:", "\\gsjs1\data",True
    End Select
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros