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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call Batch File from VB Script 2

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
New to vbscript, with a question.

I currently use Net Use in a batch file to map to several network drives at login. I would like to know if this can be converted to vbscript, and then called at login.

In batch file, I use:

net use L: \\10.110.69.120\C$ /user:username password

I would also like this to run minimized to prevent user from seeing username and password.

Any help is appreciated.
 
In vbs, to connect network drives, do the following :
Code:
public WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "L:", "\\10.110.69.120\C$", false, username, password
Water is not bad as long as it stays out human body ;-)
 
That appears to be just what I needed, but have another question.

I need to connect to 5 remote locations (L - M local drives)at login, is this possible? I also need to ensure that after log out, the mapping is disconnected.

Should this be a loop? I am getting an error when trying to connect to 2 drives, says object is already in use.

Help again is appreciated.
 
I don't know how to run automatically a vbs at logon.
For the second question (multiple connect), there's no problem as soon as the drive letter and mapped drive is different for each connections. Drives connected this way doesn't survive after logoff.
Water is not bad as long as it stays out human body ;-)
 
I was able to get the multiple drives connected, thanks.

Error I rec'ed was because the drive was taken when I was trying to run the script again.

Do you know how I could add any error handling, to check and see if the drive is taken?

Thanks again.
 
Code:
public WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
on error resume next 'begins error catching
WshNetwork.MapNetworkDrive "L:", "\\10.110.69.120\C$", false, username, password
if err.number <> 0 then
  'do here your error handling
  err.clear
  on error goto 0 'ends error catching
end if

if I helped, gimme a star !!! Water is not bad as long as it stays out human body ;-)
 
public WshNetwork
Set WshNetwork = CreateObject(&quot;WScript.Network&quot;)
Set fso = Wscript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
if fso.DriveExists(&quot;L:&quot;) Then
WshNetwork.RemoveNetworkDrive &quot;L:&quot;, True
WshNetwork.MapNetworkDrive &quot;L:&quot;, &quot;\\10.110.69.120\C$&quot;, false, username, password
Else
WshNetwork.MapNetworkDrive &quot;L:&quot;, &quot;\\10.110.69.120\C$&quot;, false, username, password
End If Regards
Steve Friday
 
To both: Targol and sFriday, Thanks. One more question:

How would I write a Case statement, to look for Drive letter?

Thanks again, both got a start from me.
 
dletter = &quot;L:&quot;
Set WshNetwork = CreateObject(&quot;WScript.Network&quot;)
Set fso = Wscript.CreateObject(&quot;Scripting.FileSystemObject&quot;)

Select Case dletter
Case &quot;L:&quot;
if fso.DriveExists(dletter) Then
WshNetwork.RemoveNetworkDrive dletter, True
WshNetwork.MapNetworkDrive dletter, &quot;\\10.110.69.120\C$&quot;, false, username, password
Else
WshNetwork.MapNetworkDrive dletter, &quot;\\10.110.69.120\C$&quot;, false, username, password
End If
Case &quot;M:&quot;
if fso.DriveExists(dletter) Then
WshNetwork.RemoveNetworkDrive dletter, True
WshNetwork.MapNetworkDrive dletter, &quot;\\10.110.69.120\D$&quot;, false, username, password
Else
WshNetwork.MapNetworkDrive dletter, &quot;\\10.110.69.120\D$&quot;, false, username, password
End If
Case Else
if fso.DriveExists(dletter) Then
WshNetwork.RemoveNetworkDrive dletter, True
WshNetwork.MapNetworkDrive dletter, &quot;\\10.110.69.120\E$&quot;, false, username, password
Else
WshNetwork.MapNetworkDrive dletter, &quot;\\10.110.69.120\E$&quot;, false, username, password
End If
End Select

Regards
Steve Friday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top