Board index » Visual Studio » Call a batch file from a vbs script

Call a batch file from a vbs script

Visual Studio153
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.



Thanks for you help and time



Jason


-
 

Re:Call a batch file from a vbs script

Easy,



Dim str_host

Set objshell = CreateObject("wscript.shell")

str_host = "127.0.0.1"

objshell.exec("ping " & str_host)









"SpiritBoy" <groups@advancepcservices.com>wrote in message

Quote
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.



Thanks for you help and time



Jason







-

Re:Call a batch file from a vbs script

SpiritBoy wrote:



Quote
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:

msdn.microsoft.com/downloads/list/webdev.asp">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:

www.microsoft.com/technet/scriptcenter/default.mspx">www.microsoft.com/technet/scriptcenter/default.mspx

-

Re:Call a batch file from a vbs script

Thanks for your responses. I was able to get the second response to

work correctly. In regards to the 1st response I do not see where you

specify the name of the batch file you are trying to call.



However I now have a new problem. Our network is composed of 300

laptops that are not on a domain. Plus the users connect to the

network thru a wireless connection. The script I have setup is pulling

a batch file off the network. I have configured the local machine

policy to open the script during the login process. The script is

trying to run before the wireless connection is able to connect to the

network where the batch file is stored. Does anyone know how to delay

the call of the login.vbs or delay the call of the batch file within

the script file?



Thanks once again for your help & time



Jason



-

Re:Call a batch file from a vbs script

SpiritBoy wrote:



Quote
Thanks for your responses. I was able to get the second response to

work correctly. In regards to the 1st response I do not see where you

specify the name of the batch file you are trying to call.



However I now have a new problem. Our network is composed of 300

laptops that are not on a domain. Plus the users connect to the

network thru a wireless connection. The script I have setup is pulling

a batch file off the network. I have configured the local machine

policy to open the script during the login process. The script is

trying to run before the wireless connection is able to connect to the

network where the batch file is stored. Does anyone know how to delay

the call of the login.vbs or delay the call of the batch file within

the script file?

Hi



Maybe go into a loop waiting for the file to show up, as the script

in this link does:



http://groups.google.co.uk/groups?selm" rel="nofollow" target="_blank">groups.google.co.uk/groups=O8WJIwWDFHA.3020%40TK2MSFTNGP09.phx.gbl





--

torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway

Administration scripting examples and an ONLINE version of

the 1328 page Scripting Guide:

www.microsoft.com/technet/scriptcenter/default.mspx">www.microsoft.com/technet/scriptcenter/default.mspx

-

Re:Call a batch file from a vbs script

Perhaps this works?



Wscript.Sleep 5000 '1000 x number of seconds to wait

Msgbox "this message shows 5 seconds after the start of the script."





"SpiritBoy" <groups@advancepcservices.com>schreef in bericht

Quote
Thanks for your responses. I was able to get the second response to

work correctly. In regards to the 1st response I do not see where you

specify the name of the batch file you are trying to call.



However I now have a new problem. Our network is composed of 300

laptops that are not on a domain. Plus the users connect to the

network thru a wireless connection. The script I have setup is pulling

a batch file off the network. I have configured the local machine

policy to open the script during the login process. The script is

trying to run before the wireless connection is able to connect to the

network where the batch file is stored. Does anyone know how to delay

the call of the login.vbs or delay the call of the batch file within

the script file?



Thanks once again for your help & time



Jason







-

Re:Call a batch file from a vbs script

Thanks Xander, that works perfect!!!



Jason



-