New to VBS, not even script kiddie.
I have a batch file I want to convert to VBS. The batch file maps a network drive using provided credentials. Works great. However I need to have it in VBS now.
The VBS I've got so far is below.
Option Explicit
On Error Resume Next
Dim wshNetwork, wshShell, wshSysEnv, colDrives, nReturnCode
Dim sGroupDrive, sGroupShare
Set wshNetwork = WScript.CreateObject("WScript.Network")
Set wshShell = WScript.CreateObject("WScript.Shell")
Set wshSysEnv = wshShell.Environment("SYSTEM")
'Define drives & shares
sGroupDrive = "S:"
sGroupShare = "\\servername\share"
If (wshSysEnv("OS") = "Windows_NT") Then
'Disconnect drives if they exists
wshNetwork.RemoveNetworkDrive sGroupDrive
'Map Drive
wshNetwork.MapNetworkDrive sGroupDrive, sGroupShare
Else
WScript.Echo "This WSH logon script supports only Windows NT." & vbNewLine & "Exiting..."
Set wshNetwork = Nothing
Set wshShell = Nothing
WScript.Quit(1)
End If
Set wshNetwork = Nothing
Set wshShell = Nothing
WScript.Quit(nReturnCode)
I have a batch file I want to convert to VBS. The batch file maps a network drive using provided credentials. Works great. However I need to have it in VBS now.
The VBS I've got so far is below.
Option Explicit
On Error Resume Next
Dim wshNetwork, wshShell, wshSysEnv, colDrives, nReturnCode
Dim sGroupDrive, sGroupShare
Set wshNetwork = WScript.CreateObject("WScript.Network")
Set wshShell = WScript.CreateObject("WScript.Shell")
Set wshSysEnv = wshShell.Environment("SYSTEM")
'Define drives & shares
sGroupDrive = "S:"
sGroupShare = "\\servername\share"
If (wshSysEnv("OS") = "Windows_NT") Then
'Disconnect drives if they exists
wshNetwork.RemoveNetworkDrive sGroupDrive
'Map Drive
wshNetwork.MapNetworkDrive sGroupDrive, sGroupShare
Else
WScript.Echo "This WSH logon script supports only Windows NT." & vbNewLine & "Exiting..."
Set wshNetwork = Nothing
Set wshShell = Nothing
WScript.Quit(1)
End If
Set wshNetwork = Nothing
Set wshShell = Nothing
WScript.Quit(nReturnCode)