Pulling from the example from the above support site, I am trying to create
a login script for our new AD domain. I am hitting a bump in the road
because I am returning a Type Mismatch: Join from the following script...
Const ACCOUNTING_GROUP ="cn=AccountingMember"
Const MARKETING_GROUP ="cn=MarketingMember"
Dim wshNetwork
Dim ADSysInfo
Dim CurrentUser
Dim strGroups
Set wshNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
Set strGroups = LCase(Join(CurrentUser.MemberOf))
If InStr(strGroups, ACCOUNTING_GROUP) Then
wshNetwork.MapNetworkDrive "w:","\\files\accounting\"
End If
If InStr(strGroups, MARKETING_GROUP) Then
wshNetwork.MapNetworkDrive "x:","\\files\marketing\"
End If
Why do I get the type mismatch?
Also is this a vailded statement that will work to map the drives if an
admin logs in.
If InStr(strGroups, MARKETING_GROUP) or InStr(strGroups,ADMIN_GROUP) Then
wshNetwork.MapNetworkDrive "x:","\\files\marketing\"
End If
Assuming Const ADMIN_GROUP =cn"IT-Admin"
This is a common problem because of the suggested script on the Microsoft
site, which has a flaw. This statement raises the error:
Set strGroups = LCase(Join(CurrentUser.MemberOf))
The Join function will raise a type mismatch error unless there are at least
2 groups in the memberOf collection. The Join function expects a "Variant()"
array, but if memberOf has one group it is "String", and if memberOf has no
groups (possible since the "primary" group is not included) it is "Empty".
The solution would be code similar to below:
===========
On Error Resume Next
arrGroups = CurrentUser.GetEx("memberOf")
If (Err.Number = 0) Then
On Error GoTo 0
strGroups = LCase(Join(arrGroups))
If InStr(strGroups, "cn=it_user,ou=West,dc=MyDomain,dc=com") Then
' Map appropriate drives.
End If
If InStr(strGroups, "cn=it_users,ou=West,dc=MyDomain,dc=com") Then
' Map appropriate drives.
End If
' More If statements...
End If
On Error GoTo 0
============
I use the GetEx method to retrieve memberOf because it returns a "Variant()"
when there is only one group, instead of a "String". An error is still
raised if memberOf is "Empty", so I trap the error.
I discuss some of these complications with regard to the memberOf attribute,
plus other ways to test for group membership, in this link:
http://www.rlmueller.net/MemberOf.htm
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Const
accounting_group ="cn=accountingmember,ou=acc,ou=backoffice,dc=mydomain,dc=com"
Const
marketing_group ="cn=marketingmember,ou=mky,ou=backoffice,dc=mydomain,dc=com"
Dim wshNetwork
Dim ADSysInfo
Dim CurrentUser
Dim strGroups
Dim arrGroups
Set wshNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
On Error Resume Next
arrGroups = CurrentUser.GetEx('MemberOf") <----Error Here
If (Err.Number = 0) Then
On Error GoTo 0
strGroups = LCase(Join(arrGroups))
If InStr(strGroups, "accounting_group") Then
wshNetwork.MapNetworkDrive "w:","\\files\accoutning\"
EndIf
If InStr(strGroups, "marketing_group") Then
wshNetwork.MapNetworkDrive "x:","\\files\marketing\"
EndIf
EndIf
On Error GoTo 0
Gill
On 8/29/07 9:32 AM, in article
BC3983EE-B7C1-424B...@microsoft.com, "John"
Const
accounting_group ="cn=accountingmember,ou=acc,ou=backoffice,dc=mydomain,dc=com"
Const
marketing_group ="cn=marketingmember,ou=mky,ou=backoffice,dc=mydomain,dc=com"
Dim wshNetwork
Dim ADSysInfo
Dim CurrentUser
Dim strGroups
Dim arrGroups
Set wshNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
On Error Resume Next
arrGroups = CurrentUser.GetEx("MemberOf")
If (Err.Number = 0) Then
On Error GoTo 0
strGroups = LCase(Join(arrGroups))
If InStr(strGroups, "accounting_group") Then
wshNetwork.MapNetworkDrive "w:","\\files\accoutning\"
EndIf <---- Error
If InStr(strGroups, "marketing_group") Then
wshNetwork.MapNetworkDrive "x:","\\files\marketing\"
EndIf
EndIf
On Error GoTo 0
Gill
On 8/29/07 11:08 AM, in article
98210DF0-AB41-4DAE...@microsoft.com, "John"
<Jo...@discussions.microsoft.com> wrote:
> My Bad. That was my fault, should have seen that one. It is now fixed and
> now the error is expected statement at line 21, char 5
>
> Const
With the changes made to End If, the login script doesn't do anything.
There are no more errors, but no mapped drives. Any ideas why?
John
2. The user you are testing only belongs to the "accounting_group" and it
looks like there is a typo in the directory you are mapping to. It looks
like you misspelled accounting in the line: "\\files\accoutning"
Gill
On 8/29/07 12:30 PM, in article
A0661D8E-FA53-4B8B...@microsoft.com, "John"
I fixed the typo in the file mapping. The user I am test is members of
Domain Users and accountingmember which is in ou=acc, ou=backoffice,
dc=mydomain, dc=com which should be taken care of with the Const statement.
I can map network drive under user account without any issues.
John
After doing so more testing, I see that I never pass the the if statement
condiction. So my question is, the first string will contain the all the
group membership, the second string will provide what to search for. The If
statement looks for a true value to map the drive. I have used msgbox to
display the strGroups and accounting_group to see what is in there before the
if statement. The accountingmember is listed in both strings, lower case so
the InStr should return a pos value and allow the drive to map... right?
John
Gill
On 8/29/07 2:46 PM, in article
9090D403-FACC-4D36...@microsoft.com, "John"
OK, here is what I was doing wrong... I was putting as the search string
"accounting_group" when it should be accounting_group. This is a const and
so InStr was compairing accounting_group when it should have been looking at
cn=accountingmember.
Thanks for all your help on this one.