Solved

VBScript to list Unavailable Mapped Drives

Posted on 2016-09-16
5
33 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
  • 2
5 Comments
 
LVL 5

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now