Avatar of ARampton
ARampton
Flag 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?
VB Script

Avatar of undefined
Last Comment
ARampton

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
D Patel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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?
ARampton

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61