Solved

VBScript to list Unavailable Mapped Drives

Posted on 2016-09-16
5
72 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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…

632 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