?
Solved

VBScript and Network Drives - A Little More Help!

Posted on 2007-10-19
4
Medium Priority
?
488 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:JamesonJendreas
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
Kragster earned 1500 total points
ID: 20110121
"H:~\\Rainbowserver\""& intUser &"$"_

is it my imagination or is there too many "'s ?  should be \\Rainbowserver\"     and looks like you have two.
0
 
LVL 1

Author Comment

by:JamesonJendreas
ID: 20110191
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
 
LVL 1

Author Comment

by:JamesonJendreas
ID: 20110935
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
 
LVL 1

Author Comment

by:JamesonJendreas
ID: 20112407
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

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question