如何为PARMAETERS提供批处理文件.BAT并使用System.Shell.execute执行它们

时间:2013-02-16 16:33:28

标签: parameters batch-file shellexecute

我正在开发一个Windows软件,我需要“System.Shell.execute” 批处理文件 功能但我希望它有两个函数(参数)

所以当我执行时:

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

它将在bat文件中运行PARAMETER1,而在ververca中运行(对于参数2)。

我想知道如何配置批量文件来执行此操作,例如:

@ECHO OFF   

PARAMETER1

::     execute some code here

PARAMETER2  

::     execute some code here

(有可能是这样吗?)

2 个答案:

答案 0 :(得分:1)

为每个功能使用批处理标签。只需GOTO第一批参数指定的标签即可。每个“函数”都可以访问以%2开头的其他参数。

@echo off
goto %1

:PARAMETER1
REM execute code here
exit /b

:PARAMETER2
REM execute code here
exit /b

答案 1 :(得分:0)

我会让我的剧本略有不同:

@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