Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass username and password in VBScript

Status
Not open for further replies.

awreneau

Technical User
Mar 26, 2003
98
0
0
US
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 submitted the post w/o finishing

My question is how do I pass credentials via the VBS script.


Thanks


P.S. Search was disabled at the time of this post, browsing didnt turn up anything.
 
This is what i use:

Code:
WSHNetwork.MapNetworkDrive "F:", "\\hostname\Share", "False", "username", "password"

 
not a very clever example to be honest.
it disconnects the drive letter without first checking if it is actually already connected to the correct share
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top