Calling a Batch File Through VB Script

Calling a Batch File Through  VB Script
Anovatek TilakGovind's picture

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.
    Function Tilak()
    dim shell
    set shell=createobject("wscript.shell")
    shell.run "INSTALL.bat"
    set shell=nothing
    
    End Function
    
  2. Save the file as .VBS
  3. Then use this VBscript in Wise Package Studio's CustomActions pane.
3.632655
Average: 3.6 (49 votes)

Nice code

PRASANNA KUMAR RAJA's picture

Nice code.....It really hepls ....

Thanks
Prasanna Kumar Raja
Sr.Application Packager
Anovatek

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.

Question about nothing ...

I found really helpful your tip, just a question about the command line :

Quote:
set shell=nothing

What is the meaning for this line in this case ?

Thanks,
Paolo

Clears the memory allocated.

Vijay.Raj's picture

Its just to clear the cache memory which is being used by the variable shell. It frees the memory once the script completes its execution.

Cheers'
Vijay

Syndicate content