Search code examples
parametersbatch-fileshellexecute

How to give PARAMETERS to batch files .BAT and execute them with System.Shell.execute


I am developing a software for windows and there is a function that I need to “System.Shell.execute” a batch file but I want it to have two functions (parameters)

So when I execute:

objShell.ShellExecute("file.bat", "PARAMETER1", "", "open", 2);

it will run the PARAMETER1 in the bat file, and viceverca (for parameter2).

I want to know how i can configure my batch file to do that, Ex:

@ECHO OFF   

PARAMETER1

::     execute some code here

PARAMETER2  

::     execute some code here

(is possible something like that?)


Solution

  • Use a batch label for each function. Simply GOTO the label specified by the 1st batch parameter. Each "function" can access additional parameters starting with %2.

    @echo off
    goto %1
    
    :PARAMETER1
    REM execute code here
    exit /b
    
    :PARAMETER2
    REM execute code here
    exit /b