Solved

Type mismatch on Join

Posted on 2003-10-26
7
732 Views
Last Modified: 2008-02-23
I have created a script to map a drive based on group membership. Here is a listing of the applicable lines in the script:

====================================================
' Create required objects
Set wshNetwork = CreateObject("WScript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set wshShell = WScript.CreateObject("WScript.Shell")
set objFSO = createobject("Scripting.FileSystemObject")

' Get users' username
Set CurrentUser = GetObject("LDAP://" & objSysInfo.UserName)

' Get user's group list
strGroups = LCase(Join(CurrentUser.MemberOf))

' Map network drives
If InStr(strGroups, "cn=Corporate") Then
      wshNetwork.MapNetworkDrive "Q:", "\\BNESRV1\CORPORATE"
End If
====================================================

When a user run the script the following error is displayed:

\\bnesrv1\netlogon\logon.vbs(11, 1) Microsoft VBScript runtime error: Type mismatch: 'Join'

The script runs OK as a Domain Admin and I have also tested the script with the user being an administrator on the local machine.

Any ideas?
Thanks in advance.


0
Comment
Question by:aaronp
  • 3
  • 2
  • 2
7 Comments
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 150 total points
ID: 9625536
Try check whether your value pass in is an array or not.

Example:

..
If IsArray(CurrentUser.MemberOf) Then
   strGroups = LCase(Join(CurrentUser.MemberOf))
Else
   strGroups = LCase(CurrentUser.MemberOf)
End if
..
0
 
LVL 7

Expert Comment

by:_agj_
ID: 9626583
This shud solve:

dim grp

' Get user's group list

strGroups = ""
for each grp in CurrentUser.MemberOf
   strGroups = strGroups & " " & LCase(grp)
next grp


use this, instead of the join thing.

Generally, something like this member of property, wud return a collection or an object collection etc.
Join works for arrays only.
0
 

Author Comment

by:aaronp
ID: 9631005
Thanks for the replies.

I tried this one:

If IsArray(CurrentUser.MemberOf) Then
   strGroups = LCase(Join(CurrentUser.MemberOf))
Else
   strGroups = LCase(CurrentUser.MemberOf)
End if

And it runs the join for a domain admin, but the Else statement for a user. Now that's get me stumped.

This one give me 'object not a collection'

for each grp in CurrentUser.MemberOf
   strGroups = strGroups & " " & LCase(grp)
next grp


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 9632948
First, we need to know what is returned from CurrentUser.MemberOf, seems that it's not a collection, which is not allow in the for each statement.

and what's the data type of CurrentUser, how you declare this variable?
0
 
LVL 7

Expert Comment

by:_agj_
ID: 9639237
run the :

If IsArray(CurrentUser.MemberOf) Then
   strGroups = LCase(Join(CurrentUser.MemberOf))    '<----set a breakpt here
Else
   strGroups = LCase(CurrentUser.MemberOf)    '<----set a breakpt here
End if

set a break point at thsoe 2 places and add the "currentuser.memberof " to the watch.
This will display the object structure. Based on that u can decide how to join the grps.
0
 
LVL 7

Accepted Solution

by:
_agj_ earned 150 total points
ID: 9639252
U could also do this stuff in anotehr way.

as in, what u want is to check if a user is in grp "Corporate" and if so, map the network drive.

There is some method to check directly if a user is a group, given the user and grp name.

>>"And it runs the join for a domain admin, but the Else statement for a user. Now that's get me stumped."

This could be coz the admin is a memeber of multiple grp and the user has only one grp.
0
 

Author Comment

by:aaronp
ID: 9639437
Ah.. the script does not return the group 'Domain Users', thanks _agj_ thats the reason why the join does not work. Thanks as well to ryancys.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now