PDA

View Full Version : calling .bat or .exe from logon script (W98)



rahab
05-16-2002, 08:55 PM
I am using a simple VBScript as my login script to map network drives for users (server=NT4 client=W98). It works great. I would like to add to this script and have it call either a .bat file or a .exe file which will update virus definitions on the users machine. How do I get the script to call the other program and run it? The .bat file is located in the same NETLOGON share as the .vbs script and basically calls the .exe which is located on another server. The .bat file runs great by itself, I just cannot figure out how to call it from within the .vbs script.

Here is the script I am using:

dim WSHNetwork, WSHShell,FileSysObj

set WSHShell=Wscript.CreateObject("Wscript.Shell")
set WSHNetwork=Wscript.CreateObject("Wscript.Network")
set FileSysObj=Wscript.CreateObject("Scripting.FileSystemObject")

ON ERROR RESUME NEXT

wscript.echo "Computer - " & WSHNetwork.ComputerName

MapDrive "J:","\\server\share"
MapDrive "K:","\\server\share2"

WSHShell.popup "Network Logon Complete!",3,"Network Logon",0+64


set WSHShell=Null
set WSHNetwork=Null
set FileSysObj=Null

Wscript.quit

'***********************************************
' MapDrive '
'***********************************************

Function MapDrive(Drive,Share)

If FileSysObj.DriveExists(share)=True Then

wscript.echo "Verified " & share & " is available"

If FileSysObj.DriveExists(Drive)=True Then

wscript.echo "Removing previous connection to " & Drive

WSHNetwork.RemoveNetworkDrive Drive

End If

wscript.echo "Mapping " & Drive & " to " & Share

WSHNetwork.MapNetworkDrive Drive, Share

Else

WSHShell.Popup "COULD NOT VERIFY " & SHARE & "! CONTACT THE NETWORK ADMIN",10,"Drive Map Error",0+48

End If
End Function

Jama
05-17-2002, 03:19 AM
Set WshShell = CreateObject("Wscript.Shell")
WshShell.run "cmd.exe" & " /c c:\MyBatchFile.Bat"

The above script will run the command interpreter “on my win2k this is cmd.exe” and have it execute MyBatchFile.bat.
The “/c” switch tells the command window to close when it’s done. This should not be necessary, but I couldn’t get it to work without a switch like /k or /c.

Pay special attention to the spaces when using “WshShell.run”. In the second part of the line where you’d put the file name, you must put one space after the “” and before the file name.

WshShell.run "notepad" & "c:\MyTextFile.txt", 1, True
This will give you an access denied error.
WshShell.run "notepad" & " c:\MyTextFile.txt ", 1, True
This will open notepad with your file.

Jama

<a target="_blank" href=http://www.jama.x5g.com> Do you like my penguin? </a>

ywhw
06-26-2002, 03:26 AM
or simply:

WshShell.run "c:\MyBatchFile.Bat",,True