Link to home
Start Free TrialLog in
Avatar of ARampton
ARamptonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBScript to list Unavailable Mapped Drives

I have been using some simple VBScript to identify a users mapped drives but have found all sample scripts I have tried omit any Mapped Drive that is Unavailable (as listed in CMD Net Use)

Because I need to remove such drives before remapping how can I identify any that are already unavailable?

Sample script lists drives nicely but only those with a Status of OK:
On Error Resume Next

Dim objNetwork, objDrives, objShell
Dim strSubst, strSubstVal, strSubstName, strEnumDrive

Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("Shell.Application")
Set objDrives = objNetwork.EnumNetworkDrives

For i = 0 to objDrives.Count - 1 Step 2
	strSubst = objShell.NameSpace(objDrives.Item(i) & Chr(92)).Self.Name 
	strSubstVal = inStr(1,strSubst, Chr(40)) - 2
	strSubstName = Mid(strSubst, 1, strSubstVal)
	strEnumDrive = strEnumDrive & "Drive Letter: " & objDrives.Item(i) & vbCrlF & _
		"Drive Name: " & strSubstName & vbCrlF & "Drive Path: " &  _
		objDrives.Item(i+1) & vbCrLf & vbCrLf
Next
MsgBox strEnumDrive ,, "All mapped Drives"

Open in new window


Any suggestions on modifying this script or using another method?
ASKER CERTIFIED SOLUTION
Avatar of D Patel
D Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ARampton

ASKER

Thanks Dhara

First script shows just what I need, second script is faster but omits anything Unavailable

Now I have identified which mapped drives are Unavailable I can't find any way of scripting their removal

Normal delete using "objNetwork.RemoveNetworkDrive strLocalDrive, True, True" does not work

Is there a way to remove an identified objItem.LocalName as found in your first script?
Used Registry entries to identify mapped drives and normal objNetwork.RemoveNetworkDrive to remove old drives

Removing drives errors but does allow remapping after next logon