VBScript and Network Drives - A Little More Help!

Hello,
I've been working on a VBScript for mapping network drives.  I was looking to be able to attach home drives through this script, where each user has their own personal share.  The shares are set up as firstname Lastinital$.  I was wondering if there was a way to use InputBox to be able to  have my employees input their first name and last initial. I think I'm pretty close, but am having trouble with writing the path to the share itself.  My script folows,

Option Explicit
Dim intUser, intDrive 'intPass, intServer
Dim strPath, strCommand, strShell
Dim objNetwork, objShell
Dim RemoveDrive
Dim bUpdateProfile, bForce

set objShell = CreateObject("WScript.Shell")
set objNetwork = CreateObject("WScript.Network")
objShell.PopUp "Please Enter First Name and Last initial with no space"
intUser = InputBox("Enter Your First Name and last initial, Do not Include a Space")
'intPass = InputBox ("Enter Your Password")
objShell.PopUp "Home Drive H:\, and Shared Drive S:\ will be installed"

 Dim arrDrive, strDrive, strShare, strDetails
bUpdateProfile = "True"
bForce = "True"

arrDrive = Array(_
      "S:~\\Ginkgo\Shared",_
      "H:~\\Rainbowserver\""& intUser &"$"_
)
On Error Resume Next
For Each strDetail in arrDrive
      StrDrive = Split (strDetails, "~") (0)
      strShare = Split (strDetails, "~") (1)

For Each strDriveDetails In arrDrive
      strDrive = Split(strDriveDetails, "~")(0)
      strShare = Split (strDriveDetails, "~")(1)       
      
WScript.Echo "Attempting to Remove Connection to " &strDrive
objNetwork.RemoveNetworkDrive strDrive, bForce, bUpdateProfile
If Err.Number <>0 Then
      WScript.Echo "Error Removing Drive " & strDrive & "-" & Err.Number & ":" & Err.Description
      Err.Clear
Else
      WScript.Echo "Removed"
End If

WScript.Echo strDrive & "Attached, happy Sharing"
objNetwork.MapNetworkDrive strDrive, strShare, bUpdateProfile
If Err.Number <>0 Then
      WScript.Echo "Error Mapping " & strDrive & "- " & Err.Number &": "& Err.Description
      Err.Clear
Else
      WScript.Echo strDrive & "Mapped Succesfully" End If
Next
WScript.Quit
Next

Thanks!
LVL 1
JamesonJendreasAsked:
Who is Participating?
 
KragsterConnect With a Mentor Commented:
"H:~\\Rainbowserver\""& intUser &"$"_

is it my imagination or is there too many "'s ?  should be \\Rainbowserver\"     and looks like you have two.
0
 
JamesonJendreasAuthor Commented:
I've tried it with both one and two, neither works.  I went with two because I'm using an editor that color codes the script, and with one it shows the "& intUser &" as being quoted, I believe this is due to the \ after rainbowserver, it seems to throw off the quotes.  
0
 
JamesonJendreasAuthor Commented:
Ok, I'm still having the same trouble, but I have cleaned it up a bit, I've defined strRemotePath to be the input plus a $, and have a pop up that confirms.  Does anyone know how to use a string variable in a network drive path?

Option Explicit
Dim inUser, intDrive 'intPass, intServer
Dim strRemotePath
Dim strPath, strCommand, strShell
Dim objNetwork, objShell
Dim RemoveDrive
Dim bUpdateProfile, bForce

set objShell = CreateObject("WScript.Shell")
set objNetwork = CreateObject("WScript.Network")
objShell.PopUp "Please Enter First Name and Last initial with no space"
inUser = InputBox("Enter Your First Name and last initial, Do not Include a Space")
'intPass = InputBox ("Enter Your Password")
objShell.PopUp "Home Drive H:\, and Shared Drive S:\ will be installed"

 Dim arrDrive, strDrive, strShare, strDetails
bUpdateProfile = "True"
bForce = "True"

strRemotePath = inUser& "$"
WScript.Echo "Home Drive Path =" & strRemotePath

arrDrive = Array(_
      "S:~\\Ginkgo\Shared",_
      "H:~\\Rainbowserver\ " & strRemotePath)

On Error Resume Next
For Each strDetail in arrDrive
      StrDrive = Split (strDetails, "~") (0)
      strShare = Split (strDetails, "~") (1)
      
WScript.Echo "Attempting to Remove Connection"
objNetwork.RemoveNetworkDrive strDrive, bForce, bUpdateProfile
If Err.Number <>0 Then
      WScript.Echo "Error Removing Drive " & strDrive & "-" & Err.Number & ":" & Err.Description
      Err.Clear
Else
      WScript.Echo "Removed"
End If

WScript.Echo strDrive & "Attached, happy Sharing"
objNetwork.MapNetworkDrive strDrive, strShare, bUpdateProfile
If Err.Number <>0 Then
      WScript.Echo "Error Mapping " & strDrive & "- " & Err.Number &": "& Err.Description
      Err.Clear
Else
      WScript.Echo strDrive & "Mapped Succesfully" End If
Next
WScript.Quit


Any Suggestions?
0
 
JamesonJendreasAuthor Commented:
Was able to fix, not too sure what the problem was.  



Option Explicit
Dim inUser, intDrive 'intPass, intServer
Dim strRemotePath
Dim strPath, strCommand, strShell
Dim objNetwork, objShell
Dim RemoveDrive
Dim bUpdateProfile, bForce

set objShell = CreateObject("WScript.Shell")
set objNetwork = CreateObject("WScript.Network")
objShell.PopUp "Welcome To the Rainbow Light Network Resource Utility v1.0, Please Read All Instructions."
objShell.PopUp "Please Enter Your First Name and Last initial with no space."
inUser = InputBox("Enter Your First Name and last initial, Do not Include a Space")
'intPass = InputBox ("Enter Your Password")
objShell.PopUp "Setting up Shared, Graphics and Home Drives"

 Dim arrDrive, strDrive, strShare, strDriveDetails
bUpdateProfile = "True"
bForce = "True"

strRemotePath = inUser& "$"
WScript.Echo "Home Drive Path =" & strRemotePath

arrDrive = Array(_
      "S:~\\Ginkgo\shared",_
      "G:~\\Rainbowserver\graphics",_
      "H:~\\Rainbowserver\" & strRemotePath)
'      )
On Error Resume Next
For Each strDriveDetails in arrDrive
      strDrive = Split(strDriveDetails, "~")(0)
      strShare = Split(strDriveDetails, "~")(1)
      
WScript.Echo strDrive & " Attempting to Remove Connection"
objNetwork.RemoveNetworkDrive strDrive, bForce, bUpdateProfile
If Err.Number <>0 Then
      WScript.Echo "Error Removing Drive " & strDrive & "-" & Err.Number & ":" & Err.Description
      Err.Clear
Else
      WScript.Echo strDrive &" Removed"
End If

WScript.Echo strDrive & " Attempting to Connect"
objNetwork.MapNetworkDrive strDrive, strShare, bUpdateProfile
If Err.Number <>0 Then
      WScript.Echo "Error Mapping " & strDrive & "- " & Err.Number &": "& Err.Description
      Err.Clear
Else
      WScript.Echo strDrive & " Mapped Succesfully" End If
Next
'Printer Install
      Dim strHPColor, strUltra, strStJohn, strPO
      Dim bColor, bPO
      Dim aColor, aPO
      strHPColor = "\\rainbowserver\HP Color LaserJet 5500 PCL 6"
      strUltra = "\\rainbowserver\Ultra Energy"
      strStJohn = "\\rainbowserver\St.Johns Bliss"
      strPO = "\\rainbowserver\PO"
      
      'Question Set UP
      bColor = False
      bPO = False
      aColor = InputBox ("Do You Require Color Printing, please type Yes or No")
      If aColor = "yes" then
            bColor= True
      Else
            bColor = False
      End If
      aPO = InputBox ("Do You Require The PO Printer? Please Type Yes Or No")
      If aPO = "yes" then
            bPO = True
      Else
            bPO = False
      End If
'Printer Install
      WScript.Echo "Now Installing Printers"
      If bColor = True Then
            WScript.Echo "HP Color 5500Dn - Now Attempting To Install"
            objNetwork.AddWindowsPrinterConnection(strHPColor)
            If Err.Number <>0 Then
                  WScript.Echo "Error Mapping Color Printer " & Err.Number & ":" & Err.Description & "Please Ignore undefined Errors"
                  Err.Clear
            Else
                  WScript.Echo "Hp Color LaserJet 5500Dn Succesfully Installed"
            End IF      
      End IF
      If bPO = True then
            WScript.Echo "Now Attempting to Install PO Printer"
            objNetwork.AddWindowsPrinterConnection(strPO)
            If Err.Number<>0 then
                  WScript.Echo "Error Mapping PO Printer" & Err.Number & ":" & Err.Description
                  Err.Clear
            Else
                  WScript.Echo "PO Printer installed"
            End If
      Else
      End If
      WScript.Echo "Now Installing Utra Energy"
      objNetwork.AddWindowsPrinterConnection(strUltra)
            If Err.Number <>0 Then
                  WScript.Echo "Error Mapping Printer" & Err.Number & ":" & Err.Descritption
                  Err.Clear
            Else
                  WScript.Echo "Ultra Energy Succesfully Installed"
            End If
      WScrip.Echo "Now Attempting to Install St.Johns Bliss"
      objNetwork.AddWindowsPrinterConnection(strStJohn)
      If Err.Number <>0 Then
            WScript.Echo "Error Mapping St.Johns Bliss " & Err.Number & ":" & Err.Description & " **PLEASE IGNORE** '500: Undefined Variable' Errors"
            Err.Clear
      Else
            WScript.Echo "St. Johns Bliss Installed!"
      End If
WScript.Echo "Finished, Thank You for Running"
WScript.Quit
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.