Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

VBScript: Select Case

Hi All,

How do I run multiple lines of code in a select case?


Select Case UserString
    Case "user1"
         WSHNetwork.MapNetworkDrive "L:", "\\server1\accounts",True
         WSHNetwork.MapNetworkDrive "P:", "\\server1\public",True
         WSHNetwork.MapNetworkDrive "X:", "\\server1\projects",True

    Case "user2"
         WSHNetwork.MapNetworkDrive "L:", "\\server1\accounts",True
         WSHNetwork.MapNetworkDrive "P:", "\\server1\public",True

End Select

Open in new window



The above code will only map the L drive.
Avatar of IanTh
IanTh
Flag of United Kingdom of Great Britain and Northern Ireland image

what os is on server 1
Avatar of detox1978

ASKER

Windows 2008, but I may also map to a Windows 2003 server.
Avatar of Qlemo
I would expect having to enclose your statements in BEGIN / END.
Can you give  me a example?


thanks
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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
I think it will work if you do it this way

Select Case UserString
    Case "user1"
         WSHNetwork.MapNetworkDrive "L:", "\\server1\accounts",True ,
         WSHNetwork.MapNetworkDrive "P:", "\\server1\public",True ,
         WSHNetwork.MapNetworkDrive "X:", "\\server1\projects",True

    Case "user2"
         WSHNetwork.MapNetworkDrive "L:", "\\server1\accounts",True ,
         WSHNetwork.MapNetworkDrive "P:", "\\server1\public",True

End Select


notice the extra comma you may need to encapsulate the whsnetwork comand as it has a ,
this way all the commands are on the same line
Turns out the drive was being mapped twice so exited
Instructions for multiple Mapped Network Drives

Copy and paste the script below into notepad.
Change the server name from "\\alan to the name of your server.
Make sure that you have not one, but two network shares on your server.
Save the file with .vbs extension e.g. MNDMultiple Drives.vbs.
Double click the logon script and check in your Windows Explorer for two new drives called : drivers on 'alan' (M:) and download reports on 'alan' (P:).
' TwoMap.vbs - Map Network Drive to M: and P:
' Example of VBScript Mapping two drives in one script.
' ----------------------------------------------------' 
Option Explicit
Dim objNetwork, strRemotePath1, strRemotePath2
Dim strDriveLetter1, strDriveLetter2 

strDriveLetter1 = "M:" 
strDriveLetter2 = "P:" 
strRemotePath1 = "\\alan\drivers" 
strRemotePath2 = "\\alan\downloads reports" 

Set objNetwork = CreateObject("WScript.Network") 

' Section which maps two drives, M: and P:
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2

' Extra code just to add a message box
WScript.Echo "Map drives " & strDriveLetter1 & " & " & strDriveLetter2

Wscript.Quit

' End of Windows Logon Script Example

Open in new window