Torgeir
Tue Mar 15 03:31:23 CST 2005
SpiritBoy wrote:
> I am new to vbs and need some help. Can anyone give me a sample
> of how you can call a batch file from within a .vbs script?
> This is going to be used in a workgroup enviroment.
Hi
I prefer to use the Run method:
'--------------------8<----------------------
sBatFile = "c:\Scripts\something.bat"
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FileExists(sBatFile) Then
MsgBox "Could not find batch file, quitting!", _
vbCritical + vbSystemModal, "Text search"
WScript.Quit
End If
' just in case there is spaces in the path
sBatFileShort = oFSO.GetFile(sBatFile).ShortPath
' Run the batch file hidden, and let the VBScript wait for
' the batch file to finish
oShell.Run sBatFileShort, 0, True
'--------------------8<----------------------
If there is a space in the bat, an alternative to use the
sBatFileShort:
oShell.Run """" & sBatFile & """", 0, True
(In VBScript, inside a quoted string, use two quotes to get one
effective)
WSH 5.6 documentation (local help file) can be downloaded
from here if you haven't got it already:
http://msdn.microsoft.com/downloads/list/webdev.asp
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx