Solved

Type mismatch on Join

Posted on 2003-10-26
7
738 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 51

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 48
Microsoft Access combo box help 2 52
TT Auto Dashboard 13 101
pop out of webbrowser1 control vba6 5 44
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

733 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