Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logon script

Status
Not open for further replies.

07softail

IS-IT--Management
Nov 29, 2007
1
US
Can anyone tell me why I am getting an error "Error: Object not a collection Code: 800A01C3. This only happens when a user is in one group. If the user is a member of two or more groups the script runs correctly. Here is a copy of the script.

'region Script Settings
'<ScriptSettings xmlns="' <ScriptPackager>
' <process>cscript.exe</process>
' <arguments />
' <extractdir>%TEMP%</extractdir>
' <files />
' <usedefaulticon>true</usedefaulticon>
' <showinsystray>false</showinsystray>
' <altcreds>false</altcreds>
' <efs>true</efs>
' <ntfs>true</ntfs>
' <local>false</local>
' <abortonfail>true</abortonfail>
' <product />
' <version>1.0.0.1</version>
' <versionstring />
' <comments />
' <includeinterpreter>false</includeinterpreter>
' <forcecomregistration>false</forcecomregistration>
' <consolemode>false</consolemode>
' <EnableChangelog>false</EnableChangelog>
' <AutoBackup>false</AutoBackup>
' </ScriptPackager>
'</ScriptSettings>
'endregion' Westwhiteland Logon Script
' VBScript to test group membership and map network dirves
' Last Modified 11-29-2007
' -----------------------------------------------------------------'

'region Logon Script Builde

'True if the user is a member of the specified group
If CheckUserGroupMembership("it") = 1 Then
MapNetworkShare "i:", "\\wwfp1\it"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("common") = 1 Then
MapNetworkShare "l:", "\\wwfp1\ww"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("ae") = 1 Then
MapNetworkShare "k:", "\\wwfp1\ae"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("engineering") = 1 Then
MapNetworkShare "o:", "\\wwfp1\eng"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("accounting") = 1 Then
MapNetworkShare "o:", "\\wwfp1\acct"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("csc") = 1 Then
MapNetworkShare "o:", "\\wwfp1\csc"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("hr") = 1 Then
MapNetworkShare "o:", "\\wwfp1\hr"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("quality") = 1 Then
MapNetworkShare "o:", "\\wwfp1\quality"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("steercom") = 1 Then
MapNetworkShare "s:", "\\wwfp1\steercom"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("iris") = 1 Then
MapNetworkShare "j:", "\\wwfp1\iris"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("aero") = 1 Then
MapNetworkShare "k:", "\\wwfp1\ae"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("operations") = 1 Then
MapNetworkShare "s:", "\\wwfp1\ops"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("hrtimesheet") = 1 Then
MapNetworkShare "i:", "\\wwfp1\eng"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("progauge") = 1 Then
MapNetworkShare "p:", "\\wwfp1\progauge"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("fuelcells") = 1 Then
MapNetworkShare "t:", "\\wwfp2\fuelcells"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("gpt") = 1 Then
MapNetworkShare "v:", "\\wwfp2\gpt"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("autocad") = 1 Then
MapNetworkShare "u:", "\\wwfp2\autocad-gpt"
End If

'True if the user is a member of the specified group
If CheckUserGroupMembership("autocadro") = 1 Then
MapNetworkShare "v:", "\\wwfp2\autocad-gpt"
End If



Function CheckUserGroupMembership(sGroup)
Set shell = CreateObject("WScript.Shell")
Set env = shell.Environment("Process")
If env("ISEXE") = "1" Then
FULLID = env("ASEUSERID")
sUser = Right(FULLID,(Len(FULLID) - (InStr(FULLID,"\"))))
Else
sUser = env("USERNAME")
End If
If sDomain = "" Then
Set rootDSE = GetObject("LDAP://rootdse")
sDomain = rootDSE.Get("DefaultNamingContext")
End If
sQuery = "Select CN,distinguishedName,aDSPath From 'LDAP://" & sDomain & "' Where objectCategory='user' AND samAccountName = '" & sUser & "'"
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConnection.Provider = ("ADsDSOObject")
oConnection.Open("Active Directory Provider")
oCommand.ActiveConnection = oConnection
oCommand.Properties("Page Size") = 1000
oCommand.Properties("Searchscope") = 2 'ADS_SCOPE_SUBTREE
oCommand.CommandText = sQuery
Set oRecordSet = oCommand.Execute
If Not oRecordset.EOF Then
Set sUserDN = GetObject(oRecordset.Fields("aDSPath"))
CheckUserGroupMembership = 0
For Each oGroup In sUserDN.MemberOf
grpArr = Split(oGroup,",")
fGroup = Join (Split(grpArr(0),"CN="),"")
If LCase(sGroup) = LCase(fGroup) Then
CheckUserGroupMembership = 1
End If
Next
Else
CheckUserGroupMembership = 0
End If
End Function

Sub MapNetworkShare(LocalDrive, NetworkPath)
'Maps specified network share to local drive
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive LocalDrive, NetworkPath
End Sub


'endregion




Thanks....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top