There would be some situations where we need to call batch file from scripts. Here the script to call: INSTALL.bat;
- Copy the below code to Notepad (or equivalent text editor, like Notepad++ or other).
Function Execute()dim shellset shell=createobject("wscript.shell")shell.run "INSTALL.bat"set shell=nothingEnd Function - Save the file as .VBS;
A small Addition
For the Run method:
Shell.Run "INSTALL.bat"
It’s good to trap any potential errors into a variable and to tell the method not to execute the next line until the current process is complete.
errTrap = Shell.Run("INSTALL.BAT", 1, True)This will return any error codes into errTrap. From there you can log the error or act on it accordingly in the script.
- "True" tells wscript/cscript to "Wait until this command is complete before running the next line." The "1" is just the window style. Not that important.
Whenever you are returning values you have to put the arguments into parenthesis.
An addition Script
Following is the template that not only return an exit code but also writes to the Event Log.
'--------------------------------------------------'GET CURRENT FOLDER PATHsLogHeader = "Install batch file"path = FileSystemObject.GetParentFolderName(WScript.ScriptFullName)If Right(path, 1) <> "\" Then path = path & "\"End IferrTrap = shell.Run(path, 1 ,True)If (errTrap = 0) Or (errTrap = 3010) Then 'WRITE EXIT CODE [0-success/3010-success&requires reboot] TO EVENTLOG shell.LogEvent vbLogSuccess, sLogHeader & "Installation completed successfully." & VbCrLf & "Exit code: " & errTrap WScript.Quit (errTrap)Else 'WRITE EXIT CODE TO EVENTLOGshell.LogEvent vbLogError, sLogHeader & "Installation failed." & VbCrLf & "Exit code: " & errTrap WScript.Quit (errTrap)End IfSet FileSystemObject = NothingSet Shell = Nothing'--------------------------------------------------
SOURCE | LINK (Symantec.com) | LANGUAGE | ENGLISH |
![]() | ![]() | ||

–> (Word)
–> (PDF)
–> (Epub)






