Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Type Mismatch: Join for Login VBS script

266 views
Skip to first unread message

John

unread,
Aug 27, 2007, 2:56:02 PM8/27/07
to
Researched from this site:
http://technet2.microsoft.com/WindowsServer/en/Library/8a268d3a-2aa0-4469-8cd2-8f28d6a630801033.mspx

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"

Richard Mueller [MVP]

unread,
Aug 27, 2007, 4:26:45 PM8/27/07
to
John wrote:

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
--


John

unread,
Aug 29, 2007, 9:32:01 AM8/29/07
to
Here is my code - syntax error line 15 char 31

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

Gilliland, Gill

unread,
Aug 29, 2007, 10:58:47 AM8/29/07
to
Looks like MemberOf is surrounded by one single quote and one double
quote...

Gill


On 8/29/07 9:32 AM, in article
BC3983EE-B7C1-424B...@microsoft.com, "John"

John

unread,
Aug 29, 2007, 11:08:10 AM8/29/07
to
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
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

Gilliland, Gill

unread,
Aug 29, 2007, 11:44:56 AM8/29/07
to
End If is two words, as opposed to one :)

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

John

unread,
Aug 29, 2007, 12:30:06 PM8/29/07
to
Gill,

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

Gilliland, Gill

unread,
Aug 29, 2007, 12:47:30 PM8/29/07
to
Possibly two reasons:
1. The user you are testing only belongs to Domain Users group, which does
not show up in the "memberOf" list.

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"

John

unread,
Aug 29, 2007, 12:58:02 PM8/29/07
to
Gill

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

John

unread,
Aug 29, 2007, 2:46:02 PM8/29/07
to
Gill,

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

Gilliland, Gill

unread,
Aug 29, 2007, 2:52:54 PM8/29/07
to
Maybe I'm not understanding the name of the group you are looking to match.
Is the group name "accounting_group" or "accountingmember" ?

Gill


On 8/29/07 2:46 PM, in article
9090D403-FACC-4D36...@microsoft.com, "John"

John

unread,
Aug 29, 2007, 3:06:02 PM8/29/07
to
I have Fixed IT!!!!

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.

0 new messages