Solved

Type mismatch on Join

Posted on 2003-10-26
7
735 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 50

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 50

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 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