We help IT Professionals succeed at work.

Select Case Userstring in login script not working

vinden
vinden asked
on
Hi,

I'm trying to map some specific drives to specific users in a vbs login script.
The setup is fairly simple but for some reason the drives are mapped for every user.

strUser = WSHNetwork.UserName
Select Case strUser
    Case "User1" Or "User2"
         WSHNetwork.MapNetworkDrive "F:", "\\SERVER\DRIVE",True
         WSHNetwork.MapNetworkDrive "Y:", "\\SERVER\DRIVE2",True
         WScript.Echo strUser
End Select

Even if I execute the script as "User3" or "UserSomethingCompletelyDifferent" it still maps the drives. That's why I added an echo at the end. The echo clearly shows a different username than the usernames in the Case expression. But still the drives are mapped.
I don't get it.

Comment
Watch Question

Maybe it has something to do with the use of OR.

Try any of this:

Case "User1","User2"

OR

Case "User1"
'--Code here
Case "User2"
'--Code again here

Author

Commented:
That's it !
I tried Case "User1","User2" and it finally works.
It seems so logical when I used "or"...Guess not.

Thanks !

Author

Commented:
Thanks both of you. Bardo was first.
Top Expert 2010

Commented:
Hello vinden,

Glad to see you got the help you needed.

Just also be aware that by default VBScript uses case sensitive text comparisons.  Thus, if the user name is
not case sensitive, you should force it to all lower or all upper case before the comparison in the Select Case.

OTOH, if the user name *is* case sensitive, you are golden :)

Regards,

Patrick

Author

Commented:
Thanks Patrick, I will implement that cause userstring is not case sensitive.
For anyone else interested, it's something like this if I'm not mistaken :
Select Case UCase(strUser)