Solved

Type mismatch on Join

Posted on 2003-10-26
7
730 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
Comment Utility
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_
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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_
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

763 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

13 Experts available now in Live!

Get 1:1 Help Now