0

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?)

tofran
  • 23
  • 5

2 Answers2

1

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
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Can you please answer the EDIT question. – tofran Feb 17 '13 at 11:48
  • 2
    @tofran - I don't understand what you are trying to do in your new 2nd question. Also, it is, (well..) a 2nd question. Please remove the EDIT from this question, and then ask a new question, and provide more explanation of what you are attempting to do. – dbenham Feb 17 '13 at 13:06
0

I would make my script a little different:

@echo off
goto %1
goto :end

:: functions

:PARAMETER1 comment1
REM execute code here
exit /b 0

:PARAMETER2 comment2
REM execute code here
if %ERRORLEVEL%==1 ECHO goto :error
exit /b 0

:error
ECHO Error occurred with arg %1
timeout 10
exit 1

:: end of script
:end
ECHO Finished
djangofan
  • 28,471
  • 61
  • 196
  • 289
  • Your `goto :end` is dead code since `goto %1` will result in fatal error if the label does not exist. So this really isn't different than my answer, just obfuscated a bit. There are multiple ways to validate the label before attempting to GOTO - for example, via IF with hard coded label strings, or FINDSTR against `%~f0`. But it doesn't really change the primary concept. – dbenham Feb 16 '13 at 18:48
  • Can you please answer the EDIT question. – tofran Feb 17 '13 at 11:48
  • Your "set" command is wrong. Besides, you already marked this question as answered. – djangofan Feb 17 '13 at 19:55