L_Welcome_MsgBox_Title_Text = "Network Drive Mapper" ' ******************************************************************************** ' * ' * WSH Network Object. ' * Dim WSHNetwork Dim colDrives, SharePoint Dim CRLF Dim Input CRLF = Chr(13) & Chr(10) Set WSHNetwork = WScript.CreateObject("WScript.Network") Function Ask(strAction) ' This function asks the user whether to perform a specific "Action" ' and sets a return code or quits script execution depending on the ' button that the user presses. This function is called at various ' points in the script below. Dim intButton intButton = MsgBox(strAction, _ vbQuestion + vbYesNo, _ L_Welcome_MsgBox_Title_Text ) Ask = intButton = vbYes End Function ' ************************************************** ' * ' * WSHNetwork.AddNetworkDrive ' * ' * Function TryMapDrive(intDrive, strShare, strUser, strPw) Dim strDrive strDrive = Chr(intDrive + 64) & ":" On Error Resume Next WSHNetwork.MapNetworkDrive strDrive, strShare, "FALSE", strUser, strPw TryMapDrive = Err.Number = 0 End Function Function TryConnect(strShare, strUser, strPw) For intDrive = 6 To 26 Step 1 If TryMapDrive(intDrive, strShare, strUser, strPw) Then Exit For Next If intDrive >= 26 Then MsgBox "Unable to connect to " & strShare & _ "There are currently no drive letters available for use. " & _ CRLF & _ "Please disconnect one of your existing network connections " & _ "and try this script again. ", _ vbExclamation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text Else strDrive = Chr(intDrive + 64) & ":" MsgBox "Connected " & strShare & " to drive " & strDrive, _ vbInformation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text End If End Function Function SelectServer() Input="" While Input="" Input = InputBox ("1. Jim's P75 C Drive" & _ CRLF &_ "2. Jim's P75 D Drive" &_ CRLF &_ "3. Central Systems" &_ CRLF &_ "4. Confidential" &_ CRLF &_ "5. Library" &_ CRLF &_ "6. Restricted" &_ CRLF &_ "7. Software Archive" &_ CRLF &_ "8. GUI library" &_ CRLF &_ "9. Online Backup" &_ CRLF &_ "0. quit" &_ CRLF &_ "Enter number for server to connect to ?", _ L_Welcome_MsgBox_Title_Text) WEnd SelectServer = Input End Function ' ************************************************* ' * MAIN FUNCTION ' * ' list of servers to try to connect to quit=n While quit = n server = SelectServer() Select Case server Case 1 TryConnect "\\JIM_PRESS\C", "", "" ' * server, username, password Case 2 TryConnect "\\JIM_PRESS\D", "", "" Case 3 TryConnect "\\SERVER3\PrestigePrj", "", "" Case 4 TryConnect "\\SERVER1\CONF", "", "" Case 5 TryConnect "\\SERVER3\SYS", "", "" Case 6 TryConnect "\\SERVER3\REST","","" Case 7 TryConnect "\\SERVER3\Software","","" Case 8 TryConnect "\\SERVER1\gui","","" Case 9 TryConnect "\\SERVER4\jim$", "", "" Case 0 quit="y" Case Else MsgBox "You didn't enter a valid number, try again" End Select WEnd ' ************************************************** ' * ' * WSHNetwork.EnumNetworkDrive ' * ' * 'Ask user whether to enumerate network drives If Ask("Do you want to enumerate connected network drives?") Then 'Enumerate network drives into a collection object of type WshCollection Set colDrives = WSHNetwork.EnumNetworkDrives 'If no network drives were enumerated, then inform user, else display 'enumerated drives If colDrives.Count = 0 Then MsgBox "There are no drives to enumerate.", _ vbInformation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text Else strMsg = "Current network drive connections: " & CRLF For i = 0 To colDrives.Count - 1 Step 2 strMsg = strMsg & CRLF & colDrives(i) & Chr(9) & colDrives(i + 1) Next MsgBox strMsg, _ vbInformation + vbOkOnly, _ L_Welcome_MsgBox_Title_Text End If End If