AdminDragon
IS-IT--Management
Hello,
I am trying to combine two VBscripts into one script. The script is to map drives according to group membership in AD when logging on to Terminal services/citrix sessions. With two of the groups however I would like to map the drives using alternate username and passwords because the server the shared folders are on are not part of AD. The scripted will map the drives that don't require alternate credentials, but fails on the others. Here is an example of my Code. Thank for the help.
On Error Resume Next
Dim oNetwork, oUser, oGroup
Dim strUser, strPassword, strDriveLetter, strHomeServer, strProfile
Dim objNetwork, objPopUp
Dim sUName, sDomain, sGroup1, sGroup2, sGroup3, sGroup4, sGroup6, sDrive1, sDrive2, sShare1,
sShare2,sDrive3, sShare3, sDrive4, sShare4
' get the username of the client currently logged in to the computer
Set objNetwork = CreateObject("WScript.Network")
Set objPopUp = CreateObject("WScript.Shell")
Set oNetwork = CreateObject("WScript.Network")
sUName = oNetwork.UserName
' ************ Configuration *************
' Put your domain name here
sDomain = "Mydomain.Local"
' Put Groups you are looking for here
sGroup1="ResED"
sGroup2="DaySchool"
sGroup3="ADP"
sGroup4="DMA"
sGroup5="HFI IT Group"
sGroup6="PsychConsult"
SGroup7="Iarcca"
' Place drive letters and associated shares here RESED
' e.g. "X:", "\\server\share" (sDrive1 = "X:", sShare1 = "\\server\share")
sDrive1 = "T:"
sShare1 = "\\HFI_Compass_LEA\smdata" 'maps schoolminder
sDrive2 = "R:"
sShare2 = "\\HFI_Compass_LEA\smwin32\gqwin" 'maps gradequick
' Place drive letters and associated shares here DAYSCHOOL
' e.g. "X:", "\\server\share" (sDrive1 = "X:", sShare1 = "\\server\share")
sDrive3 = "w:"
sShare3 = "\\SC02\smwin32\smdata" 'maps schoolminder
sDrive4 = "S:"
sShare4 = "\\SC02\gqwin" 'maps gradequick
Set oUser = GetObject("WinNT://" & sDomain & "/" & sUName)
For Each oGroup In oUser.Groups
select case oGroup.Name
' add a case for each group you may be looking for
case sGroup1 ' true for Resed
oNetwork.MapNetworkDrive sDrive1, sShare1
oNetwork.MapNetworkDrive sDrive2, sShare2
If Err.Number <> 0 Then ' THE DRIVE WAS NOT CREATED
WScript.Echo "Unable to map " & sDrive1 & " to " & sShare1 & " and unable to map " & sDrive2 & " to " &
sShare2
Err.Clear
End If
case sGroup2 ' true for DaySchool
oNetwork.MapNetworkDrive sDrive3, sShare3
oNetwork.MapNetworkDrive sDrive4, sShare4
If Err.Number <> 0 Then ' THE DRIVE WAS NOT CREATED
WScript.Echo "Unable to map " & sDrive3 & " to " & sShare3 & " and unable to map " & sDrive4 & " to " &
sShare4
Err.Clear
End If
case sGroup5 ' true for "HFI IT Group"
oNetwork.MapNetworkDrive sDrive1, sShare1
oNetwork.MapNetworkDrive sDrive2, sShare2
oNetwork.MapNetworkDrive sDrive3, sShare3
oNetwork.MapNetworkDrive sDrive4, sShare4
If Err.Number <> 0 Then ' THE DRIVE WAS NOT CREATED
WScript.Echo "Unable to map " & sDrive1 & " to " & sShare1 & " and unable to map " & sDrive2 & " to " &
sShare2 & " and unable to map " & sDrive3 & " to " & sShare3 & " and unable to map " & sDrive4 & " to " &
sShare4
Err.Clear
End If
case sGroup6 ' true for PsychConsult
strUser = "Username"
strPassword = "password"
strDriveLetter = "j:"
strHomeServer = "\\HFI_Askesis\sp1.1"
objNetwork.MapNetworkDrive strDriveLetter, strHomeServer, strProfile, strUser, strPassword
objPopUp.popup "Drive " & strDriveLetter & " connected successfully."
case sGroup7 ' true for Iarcca
strUser = "username1"
strPassword = "password1"
strDriveLetter = "P:"
strHomeServer = "\\HFI_Education2\Eon"
objNetwork.MapNetworkDrive strDriveLetter, strHomeServer, strProfile, strUser, strPassword
objPopUp.popup "Drive " & strDriveLetter & " connected successfully."
end Select
Next
'Quit the Script
wscript.quit
I am trying to combine two VBscripts into one script. The script is to map drives according to group membership in AD when logging on to Terminal services/citrix sessions. With two of the groups however I would like to map the drives using alternate username and passwords because the server the shared folders are on are not part of AD. The scripted will map the drives that don't require alternate credentials, but fails on the others. Here is an example of my Code. Thank for the help.
On Error Resume Next
Dim oNetwork, oUser, oGroup
Dim strUser, strPassword, strDriveLetter, strHomeServer, strProfile
Dim objNetwork, objPopUp
Dim sUName, sDomain, sGroup1, sGroup2, sGroup3, sGroup4, sGroup6, sDrive1, sDrive2, sShare1,
sShare2,sDrive3, sShare3, sDrive4, sShare4
' get the username of the client currently logged in to the computer
Set objNetwork = CreateObject("WScript.Network")
Set objPopUp = CreateObject("WScript.Shell")
Set oNetwork = CreateObject("WScript.Network")
sUName = oNetwork.UserName
' ************ Configuration *************
' Put your domain name here
sDomain = "Mydomain.Local"
' Put Groups you are looking for here
sGroup1="ResED"
sGroup2="DaySchool"
sGroup3="ADP"
sGroup4="DMA"
sGroup5="HFI IT Group"
sGroup6="PsychConsult"
SGroup7="Iarcca"
' Place drive letters and associated shares here RESED
' e.g. "X:", "\\server\share" (sDrive1 = "X:", sShare1 = "\\server\share")
sDrive1 = "T:"
sShare1 = "\\HFI_Compass_LEA\smdata" 'maps schoolminder
sDrive2 = "R:"
sShare2 = "\\HFI_Compass_LEA\smwin32\gqwin" 'maps gradequick
' Place drive letters and associated shares here DAYSCHOOL
' e.g. "X:", "\\server\share" (sDrive1 = "X:", sShare1 = "\\server\share")
sDrive3 = "w:"
sShare3 = "\\SC02\smwin32\smdata" 'maps schoolminder
sDrive4 = "S:"
sShare4 = "\\SC02\gqwin" 'maps gradequick
Set oUser = GetObject("WinNT://" & sDomain & "/" & sUName)
For Each oGroup In oUser.Groups
select case oGroup.Name
' add a case for each group you may be looking for
case sGroup1 ' true for Resed
oNetwork.MapNetworkDrive sDrive1, sShare1
oNetwork.MapNetworkDrive sDrive2, sShare2
If Err.Number <> 0 Then ' THE DRIVE WAS NOT CREATED
WScript.Echo "Unable to map " & sDrive1 & " to " & sShare1 & " and unable to map " & sDrive2 & " to " &
sShare2
Err.Clear
End If
case sGroup2 ' true for DaySchool
oNetwork.MapNetworkDrive sDrive3, sShare3
oNetwork.MapNetworkDrive sDrive4, sShare4
If Err.Number <> 0 Then ' THE DRIVE WAS NOT CREATED
WScript.Echo "Unable to map " & sDrive3 & " to " & sShare3 & " and unable to map " & sDrive4 & " to " &
sShare4
Err.Clear
End If
case sGroup5 ' true for "HFI IT Group"
oNetwork.MapNetworkDrive sDrive1, sShare1
oNetwork.MapNetworkDrive sDrive2, sShare2
oNetwork.MapNetworkDrive sDrive3, sShare3
oNetwork.MapNetworkDrive sDrive4, sShare4
If Err.Number <> 0 Then ' THE DRIVE WAS NOT CREATED
WScript.Echo "Unable to map " & sDrive1 & " to " & sShare1 & " and unable to map " & sDrive2 & " to " &
sShare2 & " and unable to map " & sDrive3 & " to " & sShare3 & " and unable to map " & sDrive4 & " to " &
sShare4
Err.Clear
End If
case sGroup6 ' true for PsychConsult
strUser = "Username"
strPassword = "password"
strDriveLetter = "j:"
strHomeServer = "\\HFI_Askesis\sp1.1"
objNetwork.MapNetworkDrive strDriveLetter, strHomeServer, strProfile, strUser, strPassword
objPopUp.popup "Drive " & strDriveLetter & " connected successfully."
case sGroup7 ' true for Iarcca
strUser = "username1"
strPassword = "password1"
strDriveLetter = "P:"
strHomeServer = "\\HFI_Education2\Eon"
objNetwork.MapNetworkDrive strDriveLetter, strHomeServer, strProfile, strUser, strPassword
objPopUp.popup "Drive " & strDriveLetter & " connected successfully."
end Select
Next
'Quit the Script
wscript.quit