troubleshooting Question

Login Script Issues - Drops Network Drives Randomly

Avatar of NCPros
NCProsFlag for Afghanistan asked on
Active DirectoryNetwork Management
11 Comments1 Solution577 ViewsLast Modified:
I am having issues with a script that we ran across in a domain network.  Trying to clean things up so that there is a better grasp of rights within the domain, but in the meantime the following code should work correctly, but something is causing the network drives to appear (let's say 8 drives based on the script) and then the drives will randomly disappear without notice or cause that I can see.  Is it something in my code or is it something in the Domain that I need to reference or check?

'Program Name       Login.VBS
'Author             David K.
'Description        VBS Login Script for Glen domain
'Design             Script can be set up to map network drives
'                   and printers using the IsMember("Group Name")
'                   function to determine group membership.  Script
'                   will also map drives and printers using the
'                   MapDrive() and MapPrinter() functions alone.
'                   A summary of network connections is displayed
'                   using the DisplayResources() function.
'Edit History
'                  12/16/06      Created
'                  02/11/2012    Edited by Clancy With NCP
'     declare global variables here

Option Explicit

Dim oShell, oNet, oFSO, oWshNetwork, oGroupDict, TShoot, uHome, WSHshell
Dim fs, msg, strComputer, objReg, strKeyPath, strStringValueName, afile, oExec
'     Objects go here

Set oShell = CreateObject("Wscript.Shell")
Set oNet   = CreateObject("Wscript.Network")
set oFSO   = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("WScript.Shell")

TShoot = 0  '1 to troubleshoot; 0 for normal operation
                                       'all mapping and stuff is done from'here
                                       'you should not have to change functions
                                       'unless they do not work for some'reason

If TShoot then Greeting()
                                       'you can put any combination of code in
 				       'to process the function calls
                                       'this is just a quick example

'All common Startup Stuff goes Here

	If IsMember("COMMON") Then
	MapDrive "P", "\\glen_asi_svr\common"	'All User Public folders

	end if

'Virus Removal Was Here

'---------- Home Directory ----------

	If IsMember("AUTO-SITE") Then
	uHome = "\\glen_asi_svr\personal\" & oNet.UserName	
'MapDrive "Z",
'	if NOT oNet.UserName = "avideo" then	
 		MapDrive "Z", uHome
	end if

	If IsMember("General Managers") Then
	MapDrive "J", "\\glen_asi_svr\owner" 	  'W2K Local Share
	MapDrive "L", "\\glen_asi_svr\sales"
	MapDrive "M", "\\glen_asi_svr\ps"
	MapDrive "O", "\\glen_asi_svr\dir"
	MapDrive "R", "\\glen_asi_svr\hr"
	MapDrive "W", "\\glen_asi_svr\fi"

	end if

	If IsMember("Accounting Directors") Then
	MapDrive "O", "\\glen_asi_svr\dir"
	MapDrive "R", "\\glen_asi_svr\hr"

	end if

	If IsMember("Sales") Then
	MapDrive "L", "\\glen_asi_svr\sales"	'W2K Local Share
	MapDrive "W", "\\glen_asi_svr\fi"

	end if

	If IsMember("Parts Service") Then
	MapDrive "M", "\\glen_asi_svr\ps"	'W2K Local Share

	end if

	If IsMember("Finance Managers") Then
	MapDrive "W", "\\glen_asi_svr\fi"	'W2K Local Share

	end if

	If IsMember("Internet Managers") Then
	MapDrive "V", "\\glen_asi_svr\internet"	'W2K Local Share

	end if

	If IsMember("HR") Then
	MapDrive "R", "\\glen_asi_svr\hr"	'W2K Local Share

	end if

	If IsMember("Title Clerks") Then
	MapDrive "S", "\\glen_asi_svr\vehacct"	'W2K Local Share

	end if

	If IsMember("ASI Subaru") Then
	MapDrive "T", "\\asi_svr_gss\f"

	end if

	If IsMember("ASI Ford") Then
	MapDrive "Q", "\\glen_asi_svr\g"

	end if

	If IsMember("ASI Summit") Then
	MapDrive "Y", "\\SUM_ASI_SVR\P"

	end if

                                       'find out what groups the user belongs too
Function IsMember(sGroup)
    Dim sAdsPath, oUser, oGroup

    If IsEmpty(oGroupDict) Then
        Set oGroupDict         = CreateObject("Scripting.Dictionary")
        oGroupDict.CompareMode = vbTextCompare

        sAdsPath  = oNet.UserDomain & "/" & oNet.UserName
        Set oUser = GetObject("WinNT://" & sAdsPath & ",user")

        For Each oGroup In oUser.Groups
            oGroupDict.Add oGroup.Name, "-"
        If TShoot Then Wscript.Echo("Member of Group: " & oGroup.Name)

        Set oUser = Nothing
    End If

    IsMember = CBool(oGroupDict.Exists(sGroup))

End Function

' MapDrive - Function to map a drive
Function MapDrive(ByVal strDriveLetter, ByVal strPath)
  Dim objRegExp
  Dim iDrive
  Dim bExists
  Dim colDrives

  Set objRegExp = New RegExp

  strDriveLetter = UCase (strDriveLetter)
  objRegExp.IgnoreCase  = true
  objRegExp.Pattern = "^[F-Z]$"

  If Not objRegExp.Test (strDriveLetter) Then
    MapDrive = False
    Exit Function
  End If

  strDriveLetter = strDriveLetter & ":"

  bExists = False
  Set colDrives = oNet.EnumNetworkDrives()
  For iDrive = 0 To colDrives.Count - 1 Step 2
    If colDrives.Item(iDrive) = strDriveLetter Then
      bExists = True
    End If

  If bExists Then
    oNet.RemoveNetworkDrive strDriveLetter, true
  End If
  On Error Resume Next
  oNet.MapNetworkDrive strDriveLetter, strPath
  if TShoot = 1 then oShell.PopUp "Drive " & strDriveLetter & " connected to " & strPath & " successfully.", 5, "Logon", 0
  MapDrive = True

End Function

Frank McCourry
V.P. Holland Computers, Inc.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros