Link to home
Start Free TrialLog in
Avatar of RobertGama
RobertGama

asked on

Logon Script Error - Type mismatch - Join

Below was my first attempt at a script (mostly borrowed code) and it's working fine for all but one user who is getting an error, Type Mismatch - Join.  I added a 'wscript.echo strGroups' command just after the join command and it would appear as though the string is NULL.  I'm not sure why because the user is a member of 'domain users', AND 'finance'.  Everyone is at least a member of 'domain users'.  The reason I had to use if...then.. statement rather than a select....case is that many of the users are members of multiple groups.  The user is running XP.  Any help would be appreciated. Thanks.





Const ENGINEERING_GROUP = "cn=engineering"
Const SALES_GROUP = "cn=sales"
Const FINANCE_GROUP = "cn=finance"
Const HUMANRESOURCES_GROUP = "cn=human resources"
Const DOMAINADMIN_GROUP = "cn=domain admins"
Const USERS_GROUP = "cn=domain users"

Dim oNetwork, oShell, oDrives
Dim sMessage

on error resume next

set oShell = CreateObject("WScript.Shell")
Set oNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
set oDrives = oNetwork.EnumNetworkDrives()

strGroups = LCase(Join(CurrentUser.MemberOf))

For n = 0 to oDrives.Count -1 Step 2
   oNetwork.RemoveNetworkDrive oDrives.Item(n), True, True
   If Err.Number <> 0 Then
      Err.Number = 0
   Else
      sMessage = sMessage & oDrives.Item(n) & ", "
   End If
Next

On Error Goto 0

if InStr(strGroups, ENGINEERING_GROUP) then
      oNetwork.MapNetworkDrive "z:", "\\server\engineering"
end if

if InStr(strGroups, SALES_GROUP) then
      oNetwork.MapNetworkDrive "x:", "\\server\sales"
end if

if InStr(strGroups, FINANCE_GROUP) then
      oNetwork.MapNetworkDrive "s:", "\\server\finance"
end if

if InStr(strGroups, HUMANRESOURCES_GROUP) then
      oNetwork.MapNetworkDrive "h:", "\\server\human resources"
end if

if InStr(strGroups, DOMAINADMIN_GROUP) then
      oNetwork.MapNetworkDrive "y:", "\\server\programs"
      oNetwork.MapNetworkDrive "m:", "\\server\maxtor"
end if

if InStr(strGroups, DOMAINUSERS_GROUP) then
      oNetwork.MapNetworkDrive "p:", "\\server\amstel public"
      oNetwork.MapNetworkDrive "u:", "\\server\"  & oNetwork.UserName
end if
Avatar of Little_Crow
Little_Crow

I'm not too sure, as I've only really dealt with Netware login scripts, and they generally aren't as bad as that.

Going by the error message I would guess that that users username has a number or perhaps a symbol in it that no others do, not knowing your username policy I can't be sure.
I'm probably clutching at straws, but it may give you something to go on.
ASKER CERTIFIED SOLUTION
Avatar of Colosseo
Colosseo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RobertGama

ASKER

Yes, the script works for other users belonging to multiple groups including myself.  The usernames are all of the same format: FnameLname

I'll changing the strGroups asignment and see how it goes.  

By the way, do you guys know how to test a script for a user without physically going to their machine or having to logon as them?  

Thanks.


Well to test it for a specific user you would have to change this line

Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)

Right now it is getting the current users username

you could change the code to this currently:

Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)

new:

Set ADSysInfo = CreateObject("ADSystemInfo")
strUsername = ADSysInfo.UserName
Set CurrentUser = GetObject("LDAP://" & strUsername)

Then when you want to run it for a specific user you can change

ADSysInfo.UserName to  "JohnSmith" (or the name of the user you want to test it for)

Scott
Thanks Scott.

For each oGroup in CurrentUser.Groups
  ' Add the lowercase group to the return string
  strGroups = strGroups & Lcase(oGroup.name)
next

...worked like a charm.  After I ran the script the user had the correct drives mapped.  

There was actually a persistent network drive also that I couldn't seem to get rid of.  Even using net use * /del.   After some searching in the forum I found that I had to change the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Network\Persistent Connections\SaveConnections=No

I'll put this here for others reference on the following subject: network drive won't disconnect / network path not found.

I'll try your suggestion for testing a specific user.

Thanks again,

Rob.
your welcome, thanks for the grade

Scott
I when I changed:
strUsername = ADSysInfo.UserName
to
strUsername = "SomeUsername"

it didn't seem to work, is there a way to search the AD for that username? Or is there another way to accomplish this? Does this work for you?

Thanks.
After a fashion thats what is being done by

Set CurrentUser = GetObject("LDAP://" & strUsername)

it is trying to find the user with the entered username.

have you tried running it with your own username?

Scott
Here is the current script I am running.   (There are sections of old code that are commented out)  Nothing appears to be happening.  The only thing I see is the output of the echo command for the strUserName.





Const ENGINEERING_GROUP = "cn=engineering"
Const SALES_GROUP = "cn=sales"
Const FINANCE_GROUP = "cn=finance"
Const HUMANRESOURCES_GROUP = "cn=human resources"
Const DOMAINADMIN_GROUP = "cn=domain admins"
Const USERS_GROUP = "cn=domain users"

Dim oNetwork, oShell, oDrives
Dim sMessage, strUserName

on error resume next

set oShell = CreateObject("WScript.Shell")
Set oNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")

strUsername ="RobertGama"    
Set CurrentUser = GetObject("LDAP://" & strUsername)
'Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
WScript.Echo "User: " & strUsername 'ADSysInfo.UserName  

set oDrives = oNetwork.EnumNetworkDrives()

for each oGroup in CurrentUser.Groups
      strGroups = strGroups & Lcase(oGroup.name)
next

'strGroups = LCase(Join(CurrentUser.MemberOf))

For n = 0 to oDrives.Count -1 Step 2
   oNetwork.RemoveNetworkDrive oDrives.Item(n), True, True
   If Err.Number <> 0 Then
      Err.Number = 0
   Else
      sMessage = sMessage & oDrives.Item(n) & ", "
   End If
Next

On Error Goto 0

if InStr(strGroups, ENGINEERING_GROUP) then
      oNetwork.MapNetworkDrive "z:", "\\server\engineering"
end if

if InStr(strGroups, SALES_GROUP) then
      oNetwork.MapNetworkDrive "x:", "\\server\sales"
end if

if InStr(strGroups, FINANCE_GROUP) then
      oNetwork.MapNetworkDrive "s:", "\\server\finance"
end if

if InStr(strGroups, HUMANRESOURCES_GROUP) then
      oNetwork.MapNetworkDrive "h:", "\\server\human resources"
end if

if InStr(strGroups, DOMAINADMIN_GROUP) then
      oNetwork.MapNetworkDrive "y:", "\\server\programs"
      oNetwork.MapNetworkDrive "m:", "\\server\maxtor"
end if

if InStr(strGroups, DOMAINUSERS_GROUP) then
      oNetwork.MapNetworkDrive "p:", "\\server\amstel public"
      oNetwork.MapNetworkDrive "u:", "\\server\"  & oNetwork.UserName
end if

so for yourself when you run

WScript.Echo "User: " & strUsername

do you get the same result as

WScript.Echo "User: " & ADSysInfo.UserName

?
No, they are not the same.

The first one is:
User: RobertGama

And the second is:
User: CN=Robert Gama, OU=Richmond Hill, DC=Amstel,DC=local

I tried entering the full string as well for the username but that did not work.

Is there a way to iterate through all of the usernames in the AD?  It doesn't seem to find a user.

Thanks.