Avatar of detox1978
detox1978
Flag 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.
VB ScriptScripting LanguagesWindows Batch

Avatar of undefined
Last Comment
Anuradha Goli

8/22/2022 - Mon
IanTh

what os is on server 1
detox1978

ASKER
Windows 2008, but I may also map to a Windows 2003 server.
Qlemo

I would expect having to enclose your statements in BEGIN / END.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
detox1978

ASKER
Can you give  me a example?


thanks
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
IanTh

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
detox1978

ASKER
Turns out the drive was being mapped twice so exited
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Anuradha Goli

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