[gptalk] New Twist on old problem - Script set to wait on network - but inside script network names not resolved
- From: <Booker.Washington@xxxxxxxxxxxxxx>
- To: <gptalk@xxxxxxxxxxxxx>
- Date: Wed, 19 Nov 2008 15:56:17 -0500
OK, I have the script below, and inside of the GPO, the settings are set for
Always wait for the network at computer startup and logon
And
Run logon scripts synchronously
But intermittently (And only once thus far), when it tries to map a drive, I
will get an error that the network name could not be found.
If I log off and log back on, then no problem.
Could I be missing a setting to make sure everything involved with name
recognition is initialized and ready to resolve names
Script contents below
Option Explicit
Dim objSysInfo, objNetwork, strUserPath, objUser
Dim adoCommand, adoConnection, strBase, strAttributes
Dim objGroupList
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
'Removes curent mappings
On Error Resume Next
objNetwork.RemoveNetworkDrive "L:", True, True
objNetwork.RemoveNetworkDrive "J:", True, True
objNetwork.RemoveNetworkDrive "Z:", True, True
objNetwork.RemoveNetworkDrive "R:", True, True
objNetwork.RemoveNetworkDrive "N:", True, True
objNetwork.RemoveNetworkDrive "O:", True, True
objNetwork.RemoveNetworkDrive "U:", True, True
objNetwork.RemoveNetworkDrive "S:", True, True
objNetwork.RemoveNetworkDrive "M:", True, True
objNetwork.RemoveNetworkDrive "I:", True, True
objNetwork.RemoveNetworkDrive "K:", True, True
objNetwork.RemoveNetworkDrive "Z:", True, True
objNetwork.RemoveNetworkDrive "X:", True, True
objNetwork.RemoveNetworkDrive "Y:", True, True
objNetwork.RemoveNetworkDrive "Q:", True, True
On Error GoTo 0
If (IsMember(objUser, "GTS IT Services Group") = True) Then
objNetwork.MapNetworkDrive "Y:", _
"\\filesrvr-01.domain.com\com\shares\groups\IT services", False
End If
If (IsMember(objUser, "GTS Career Services") = True) Then
objNetwork.MapNetworkDrive "L:", _
"\\filesrvr-01.domain.com\com\shares\groups\Career Services", False
objNetwork.MapNetworkDrive "J:", _
"\\filesrvr-01.domain.com\com\shares\groups\Career Svcs_Act", False
objNetwork.MapNetworkDrive "Z:", _
"\\filesrvr-01.domain.com\com\shares\groups\Undergraduate Office", False
End If
If (IsMember(objUser, "GTS Career Services SAs") = True) Then
objNetwork.MapNetworkDrive "L:", _
"\\filesrvr-01.domain.com\com\shares\groups\Career Services", False
objNetwork.MapNetworkDrive "J:", _
"\\filesrvr-01.domain.com\com\shares\groups\Career Svcs_Act", False
objNetwork.MapNetworkDrive "Z:", _
"\\filesrvr-01.domain.com\com\shares\groups\Undergraduate Office", False
End If
If (IsMember(objUser, "GTS CIBER") = True) Then
objNetwork.MapNetworkDrive "R:", _
"\\filesrvr-01.domain.com\com\shares\groups\CIBER", False
End If
If (IsMember(objUser, "GTS Communications") = True) Then
objNetwork.MapNetworkDrive "R:", _
"\\filesrvr-01.domain.com\com\shares\groups\Communications", False
objNetwork.MapNetworkDrive "N:", _
"\\filesrvr-01.domain.com\com\shares\groups\DeanSuite", False
End If
If (IsMember(objUser, "GTS Communications Share Guest access") = True) Then
objNetwork.MapNetworkDrive "R:", _
"\\filesrvr-01.domain.com\com\shares\groups\Communications", False
objNetwork.MapNetworkDrive "N:", _
"\\filesrvr-01.domain.com\com\shares\groups\DeanSuite", False
End If
If (IsMember(objUser, "GTS Dean Suite non HR") = True) Then
objNetwork.MapNetworkDrive "L:", _
"\\filesrvr-01.domain.com\com\shares\groups\Building Operations", False
objNetwork.MapNetworkDrive "N:", _
"\\filesrvr-01.domain.com\com\shares\groups\DeanSuite", False
objNetwork.MapNetworkDrive "O:", _
"\\filesrvr-01.domain.com\com\shares\groups\Accounting", False
objNetwork.MapNetworkDrive "U:", _
"\\filesrvr-01.domain.com\com\shares\groups\Graduate Assistantship", False
objNetwork.MapNetworkDrive "S:", _
"\\filesrvr-01.domain.com\com\shares\groups\Accounting\FAcS", False
End If
If (IsMember(objUser, "GTS Development") = True) Then
objNetwork.MapNetworkDrive "L:", _
"\\filesrvr-01.domain.com\com\shares\groups\Development", False
objNetwork.MapNetworkDrive "R:", _
"\\filesrvr-01.domain.com\com\shares\groups\Communications", False
objNetwork.MapNetworkDrive "M:", _
"\\filesrvr-01.domain.com\com\shares\groups\Development\Student Share", False
objNetwork.MapNetworkDrive "N:", _
"\\filesrvr-01.domain.com\com\shares\groups\DeanSuite", False
End If
If (IsMember(objUser, "GTS Development SAs") = True) Then
objNetwork.MapNetworkDrive "M:", _
"\\filesrvr-01.domain.com\com\shares\groups\Development\Student Share", False
End If
If (IsMember(objUser, "GTS Eview Users") = True) Then
objNetwork.MapNetworkDrive "Y:", _
"\\filesrvr-01.domain.com\com\shares\groups\eview", False
End If
If (IsMember(objUser, "GTS Executive Masters") = True) Then
objNetwork.MapNetworkDrive "I:", _
"\\filesrvr-01.domain.com\com\shares\groups\Executive Education", False
objNetwork.MapNetworkDrive "J:", _
"\\filesrvr-01.domain.com\com\shares\groups\EMSMOT_Act", False
objNetwork.MapNetworkDrive "K:", _
"\\filesrvr-01.domain.com\com\shares\groups\EMSMOT", False
objNetwork.MapNetworkDrive "O:", _
"\\filesrvr-01.domain.com\com\shares\groups\Accounting", False
objNetwork.MapNetworkDrive "L:", _
"\\filesrvr-01.domain.com\com\shares\groups\Executive Programs", False
End If
If (IsMember(objUser, "GTS Executive Programs") = True) Then
objNetwork.MapNetworkDrive "I:", _
"\\filesrvr-01.domain.com\com\shares\groups\Executive Education", False
objNetwork.MapNetworkDrive "J:", _
"\\filesrvr-01.domain.com\com\shares\groups\EMSMOT_Act", False
objNetwork.MapNetworkDrive "K:", _
"\\filesrvr-01.domain.com\com\shares\groups\EMSMOT", False
objNetwork.MapNetworkDrive "O:", _
"\\filesrvr-01.domain.com\com\shares\groups\Accounting", False
objNetwork.MapNetworkDrive "L:", _
"\\filesrvr-01.domain.com\com\shares\groups\Executive Programs", False
End If
If (IsMember(objUser, "GTS Explab Share participants") = True) Then
objNetwork.MapNetworkDrive "Z:", _
"\\filesrvr-01.domain.com\com\shares\groups\Explab", False
End If
If (IsMember(objUser, "GTS Graduate Office") = True) Then
objNetwork.MapNetworkDrive "M:", _
"\\filesrvr-01.domain.com\com\shares\groups\Graduate Office", False
End If
If (IsMember(objUser, "GTS Grad Assistant Share") = True) Then
objNetwork.MapNetworkDrive "U:", _
"\\filesrvr-01.domain.com\com\shares\groups\Graduate Assistantship", False
End If
If (IsMember(objUser, "GTS HR staff") = True) Then
objNetwork.MapNetworkDrive "X:", _
"\\filesrvr-01.domain.com\com\shares\groups\Building Operations", False
objNetwork.MapNetworkDrive "N:", _
"\\filesrvr-01.domain.com\com\shares\groups\DeanSuite", False
objNetwork.MapNetworkDrive "O:", _
"\\filesrvr-01.domain.com\com\shares\groups\Accounting", False
objNetwork.MapNetworkDrive "Y:", _
"\\filesrvr-01.domain.com\com\shares\groups\Communications", False
objNetwork.MapNetworkDrive "R:", _
"\\filesrvr-01.domain.com\com\shares\groups\Human Resources", False
objNetwork.MapNetworkDrive "Q:", _
"\\filesrvr-01.domain.com\com\shares\groups\Accounting\Pcard", False
End If
If (IsMember(objUser, "ILE Office") = True) Then
objNetwork.MapNetworkDrive "J:", _
"\\filesrvr-01.domain.com\com\shares\groups\Institute for LE", False
End If
If (IsMember(objUser, "ILE GRAs") = True) Then
objNetwork.MapNetworkDrive "J:", _
"\\filesrvr-01.domain.com\com\shares\groups\Institute for LE", False
End If
If (IsMember(objUser, "GTS Tiger Share participants") = True) Then
objNetwork.MapNetworkDrive "R:", _
"\\filesrvr-01.domain.com\com\shares\groups\Tiger", False
End If
If (IsMember(objUser, "GTS Undergraduate Office") = True) Then
objNetwork.MapNetworkDrive "M:", _
"\\filesrvr-01.domain.com\com\shares\groups\Undergraduate Office", False
End If
If (IsMember(objUser, "GTS Recruiting Share Access") = True) Then
objNetwork.MapNetworkDrive "Q:", _
"\\filesrvr-01.domain.com\com\shares\groups\Recruiting", False
End If
If (IsMember(objUser, "GTS Faculty") = True) Then
objNetwork.MapNetworkDrive "S:", _
"\\filesrvr-01.domain.com\com\shares\groups\Accounting\FAcS", False
End If
Function IsMember(ByVal objADObject, ByVal strGroupNTName)
' Function to test for group membership.
' objADObject is a user or computer object.
' strGroupNTName is the NT name (sAMAccountName) of the group to test.
' objGroupList is a dictionary object, with global scope.
' Returns True if the user or computer is a member of the group.
' Subroutine LoadGroups is called once for each different objADObject.
Dim objRootDSE, strDNSDomain
' The first time IsMember is called, setup the dictionary object
' and objects required for ADO.
If (IsEmpty(objGroupList) = True) Then
Set objGroupList = CreateObject("Scripting.Dictionary")
objGroupList.CompareMode = vbTextCompare
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Search entire domain.
strBase = "<LDAP://" & strDNSDomain & ">"
' Retrieve NT name of each group.
strAttributes = "sAMAccountName"
' Load group memberships for this user or computer into dictionary
' object.
Call LoadGroups(objADObject)
Set objRootDSE = Nothing
End If
If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then
' Dictionary object established, but group memberships for this
' user or computer must be added.
Call LoadGroups(objADObject)
End If
' Return True if this user or computer is a member of the group.
IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\" _
& strGroupNTName)
End Function
Sub LoadGroups(ByVal objADObject)
' Subroutine to populate dictionary object with group memberships.
' objGroupList is a dictionary object, with global scope. It keeps track
' of group memberships for each user or computer separately. ADO is used
' to retrieve the name of the group corresponding to each objectSid in
' the tokenGroup array. Based on an idea by Joe Kaplan.
Dim arrbytGroups, k, strFilter, adoRecordset, strGroupName, strQuery
' Add user name to dictionary object, so LoadGroups need only be
' called once for each user or computer.
objGroupList.Add objADObject.sAMAccountName & "\", True
' Retrieve tokenGroups array, a calculated attribute.
objADObject.GetInfoEx Array("tokenGroups"), 0
arrbytGroups = objADObject.Get("tokenGroups")
' Create a filter to search for groups with objectSid equal to each
' value in tokenGroups array.
strFilter = "(|"
If (TypeName(arrbytGroups) = "Byte()") Then
' tokenGroups has one entry.
strFilter = strFilter & "(objectSid=" _
& OctetToHexStr(arrbytGroups) & ")"
ElseIf (UBound(arrbytGroups) > -1) Then
' TokenGroups is an array of two or more objectSid's.
For k = 0 To UBound(arrbytGroups)
strFilter = strFilter & "(objectSid=" _
& OctetToHexStr(arrbytGroups(k)) & ")"
Next
Else
' tokenGroups has no objectSid's.
Exit Sub
End If
strFilter = strFilter & ")"
' Use ADO to search for groups whose objectSid matches any of the
' tokenGroups values for this user or computer.
strQuery = strBase & ";" & strFilter & ";" _
& strAttributes & ";subtree"
adoCommand.CommandText = strQuery
Set adoRecordset = adoCommand.Execute
' Enumerate groups and add NT name to dictionary object.
Do Until adoRecordset.EOF
strGroupName = adoRecordset.Fields("sAMAccountName").Value
objGroupList.Add objADObject.sAMAccountName & "\" _
& strGroupName, True
adoRecordset.MoveNext
Loop
adoRecordset.Close
Set adoRecordset = Nothing
End Sub
Function OctetToHexStr(ByVal arrbytOctet)
' Function to convert OctetString (byte array) to Hex string,
' with bytes delimited by \ for an ADO filter.
Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr & "\" _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function
Booker T. Washington III
Systems Support Specialist
Other related posts: