Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript to list Unavailable Mapped Drives

Posted on 2016-09-16
5
Medium Priority
?
76 Views
Last Modified: 2016-10-31
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?
0
Comment
Question by:ARampton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
D Patel earned 2000 total points
ID: 41802971
Following script takes long time to enum all shares, active, disconnected, unavailable

---------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkConnection",,48)
For Each objItem in colItems
    Wscript.Echo objItem.LocalName, objItem.RemoteName, objItem.ConnectionState
Next

Open in new window

------

Compare to this following code is very fast

-------
Set objNetwork = WScript.CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
 Wscript.Echo colDrives.Item(i) & vbTab & colDrives.Item (i + 1)
Next

Open in new window

-------
0
 

Author Comment

by:ARampton
ID: 41805050
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?
0
 

Author Closing Comment

by:ARampton
ID: 41866697
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
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question