Board index » Visual Studio » Call a batch file from a vbs script
|
tskogstrom
|
|
tskogstrom
|
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 - |
| Scripting
Registered User |
Mon Mar 14 17:53:47 CST 2005
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 QuoteI am new to vbs and need some help. Can anyone give me a sample of how - |
| Torgeir
Registered User |
Tue Mar 15 03:31:23 CST 2005
Re:Call a batch file from a vbs script
SpiritBoy wrote:
QuoteI am new to vbs and need some help. Can anyone give me a sample 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 - |
| SpiritBoy
Registered User |
Wed Mar 16 09:37:19 CST 2005
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 - |
| Torgeir
Registered User |
Wed Mar 16 09:46:53 CST 2005
Re:Call a batch file from a vbs script
SpiritBoy wrote:
QuoteThanks for your responses. I was able to get the second response to 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 - |
| Xander
Registered User |
Wed Mar 16 09:52:06 CST 2005
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 QuoteThanks for your responses. I was able to get the second response to - |
| SpiritBoy
Registered User |
Wed Mar 16 13:23:03 CST 2005
Re:Call a batch file from a vbs script
Thanks Xander, that works perfect!!!
Jason - |
