Login - Register - Welcome, HBooker!   

   
 
–> (Word) –> (PDF) –> (Epub)
This article has been published 1 year, 114 days ago

There would be some situations where we need to call batch file from scripts. Here the script to call: INSTALL.bat;

  1. 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
  2. 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
HeelpBook (1078 Posts)

Hello! Certainly you don't know us....we're a crew of computer's enthusiast, but we know that there're a lot of people searching constantly answers for their everyday problems with technology and computers, but we know also that there are people searching for answers, on web, for their everyday problems but NOT with technology, but for anything else. So, OUR first goal will be to give you quality answers to questions already done on web (forums, personal blogs, etc.), collect them and present them to you, integrating them if necessary, on this portal. Obviously, we will give you links to the source of these answers, giving, at the same time, credits to his author/site. We want to be your safe haven to your answers.




Facebook Twitter Email Plusone Linkedin Stumbleupon Delicious Digg
   
© 2011 - 2013 HeelpBook - Today is: 19/5/2013 Last updated: January 26, 2012 at 22:00 pm Get helped -