vinden
asked on
Select Case Userstring in login script not working
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 "UserSomethingCompletelyDi fferent" 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.
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
WSHNetwork.MapNetworkDrive
WScript.Echo strUser
End Select
Even if I execute the script as "User3" or "UserSomethingCompletelyDi
I don't get it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks both of you. Bardo was first.
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
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
ASKER
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)
For anyone else interested, it's something like this if I'm not mistaken :
Select Case UCase(strUser)
ASKER
I tried Case "User1","User2" and it finally works.
It seems so logical when I used "or"...Guess not.
Thanks !