how to call more than 1 batch files in a vbscript? - vbscript

I am using the following code to call a batch file:
dim shell
set shell=createobject("wscript.shell")
shell.run "a.bat D:\a"
set shell=nothing
How do I call more than 1 batch file, so that when the 1st file's execution is over the 2nd file is executed.
as always, I really appreciate any help offered.

Below
shell.run "a.bat D:\a"
add another line with another
shell.run "b.bat ...."
Or create a batch file that calls all the other batch files, and call that batch file from your script.

Option explicit
Dim oShell
set oShell = Wscript.CreateObject("WScript.Shell")
oShell.Run "RunAs /noprofile /user:Admininistrator ""%comspec% /c 1stcommand && 2ndcommand && 3rdcommand""", 1, false
WScript.Sleep 1000
oShell.Sendkeys "AdmininistratorPassword~"
Wscript.Quit

Related

Run batch file with parameters

I would like to run a batch file with some extra character at the end.
If I write it directly to cmd it is working, like change directory to "c:\Users\Public\Uploader\" and write the following: start.bat "cmd:file.import c:\Users\tom\Desktop\a.xml"
I do not know how to write it in VBScript, because the following script is not working:
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory="C:\Users\Public\Uploader\"
WshShell.Run "start.bat" & "cmd:file.import C:\Users\tom\Desktop\a.xml"
The a.xml should dynamically change based on the last modified file in the folder.
Thank you for your help!
If you're trying to duplicate what you're doing in the command prompt, you need to add a space between the batch file name and its arguments. You also need to add the quotes.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory="C:\Users\Public\Uploader\"
WshShell.Run "start.bat " & chr(34) & "cmd:file.import C:\Users\tom\Desktop\a.xml" & chr(34)

Deleting Winzip Command Line Add On 2.2 vbs

I'm trying to delete a file like winzip command line using this code
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\Program Files\WinZip\wzuninst.exe wzcline C:\Program Files\WinZip\wzclun.dll")
When I run it on cmd it says Bad name or number. Can someone clarify it for me?
That's not a valid command line.
If you want to run a program you use wshshell.run.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /k dir c:\windows\*.*"

VB Script to open multiple programs at once

Right im looking for a script that I can click on after I have logged in to open various programs just to save me a bit of time. I have managed to get a script to open one but as a bit of a newbie can someone provide advice.
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run """C:\Program Files (x86)\servicecenter\Run\scguiw32.exe "" ""-
express:dvla.servicecenter.fs.fujitsu.com.12680"""
Set objShell = Nothing
You might be overthinking it a bit to use VBScript or Powershell for this job. A batch file will work.
#echo off
start "c:\Program Files\Folder 1\program.exe"
start "c:\Program Files\Folder 2\program.exe" -switch -argument
exit
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("Path to program")
wscript.sleep (100)
objShell.Run("Path to program")
wscript.sleep (100)
wscript.quit
I do not have scguiw32.exe, so I created simple script which opens file in notepad and in word.
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run "C:\Windows\notepad.exe c:\dump.txt"
objShell.Run """C:\Program Files (x86)\Microsoft Office\Office14\winword.exe"" c:\dump.txt"
Set objShell = Nothing
BTW Instead of vbscript you can use now powershell, and powershell script is much more easy to understand. For example above one will be: Create run.ps1 with content
& 'C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE' c:\dump.txt
notepad.exe C:\dump.txt
Click it right-click and choose Run with Powershell
Here is how to use vbscript to create an array of programs you want to run and then execute each one.
'---Declare Variables
Dim objShell, strprogram1, strProgram2, colprograms, item
'---Create Scripting Shell Object
Set objShell = CreateObject("WScript.Shell")
'---Create Program Variables
strProgram1 = """C:\Program Files (x86)\servicecenter\Run\scguiw32.exe"" ""-express:dvla.servicecenter.fs.fujitsu.com.12680"""
strProgram2 = "C:\Windows\notepad.exe C:\Dump.txt"
'---Add Variables to an Array
colPrograms = Array(strProgram1,strProgram2)
'---Run each program in the array once
For Each item In colprograms
objShell.Run item
Next
WScript.Echo "Done."

VBScript If then, trying to run exe with arguments

Option Explicit
Dim oFSO, oTxtFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists("c:\users\Installed.txt") Then
WScript.Quit
Else
Set WshShell = CreateObject("WScript.Shell")
WshShell.Exec("\\1.1.1.1\software\1.exe -s /s -a ns=1.5.3.2")
Set oTxtFile = oFSO.CreateTextFile("c:\users\Installed.txt")
End If
My Code is above. I am getting an error when running my vbs. Line 13 char 1 variable is undefined. "WSHShell".
The goal is to have this vbs check for a file. If the file exists then end. If the file is not found run an installer with arguments, then create the file.
Any help would be great.
Thanks,
If you use "Option Explicit" - as you should - all variables must be (Re)Dim-ed. So add WshShell to you Dim statement.

how do I execute several programs consecutively in vbs

I have a couple of applications that I would like to execute one following the other.
how do I do this?
I tried this but the second task never executed.
on error resume next
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files\my folder\do task1.exe.vbs"""
WshShell.Run """C:\Program Files\my folder\do task2.exe.vbs"""
msgbox "Finished tasks"
update:
notes found on WshShell.Run click here
What you are missing (per ISDi's answer) is the third parameter of Run, which tells it to not wait for the program to quit (false), before continuing code exection.
Try (If you want to put your code in a subroutine, which if good coding practice for repeat activities):
'Place all of the following in a .vbs file
Sub RunApplication(ByVal sFile)
Dim WShell : Set WShell = CreateObject("WScript.Shell")
WShell.Run Chr(34) & sFile & Chr(34), 8, false
End Sub
'Executing apps.
RunApplication "C:\Program Files\my folder\task1.exe"
RunApplication "C:\Program Files\my folder\task2.exe"
The Run method of WScript.shell has an optional parameter that can halt execution of the script until the Run method returns.
Try:
WshShell.Run("""C:\YourPathTo\task1.exe""", 1, true)
The third parameter, true in the line above tells the interpreter to wait until this task exits before continuing to the next line of the script.
-isdi-

Resources