我正在尝试为客户端创建一个html页面,从中他可以在任何远程桌面上启动或停止特定的窗口服务。总数没有。范围内的服务是20左右。而不是创建20(开始)+ 20(停止)+ 20(重新启动)批处理文件,我想有1个批处理文件与if else条件,我可以在javascript函数中传递参数。 html页面的代码如下:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
MyObject = new ActiveXObject("WScript.Shell")
function start()
{
MyObject.Run("\"E:\\start.bat\"");
}
function stop()
{
MyObject.Run("\"E:\\stop.bat\"");
}
function restart()
{
MyObject.Run("\"E:\\restart.bat\"");
}
</script>
<title>Our Company</title>
</head>
<body>
<table background-color:#f1f1c1; border="1" style="width:50%" align="center">
<tr>
<th style="text-align:center">Instance Name</th>
<th style="text-align:center">Accessible URL</th>
<th style="text-align:center">Status</th>
<th style="text-align:center">Start</th>
<th style="text-align:center">Stop</th>
<th style="text-align:center">Restart</th>
</tr>
<tr height="70%">
<td style="text-align:center">netadds</td>
<td style="text-align:center">
<a href="http://localhost/">localhost:netadds</a></td>
<td style="text-align:center">Running</td>
<td style="text-align:center"><button onclick="start()">Start</button></td>
<td style="text-align:center"><button onclick="stop()">Stop</button></td>
<td style="text-align:center"><button onclick="restart()">Restart</button> </td>
</tr>
</table>
</body>
</html>
和start.bat中的代码是:
@echo off
net start AMAPTestJetty8i0T1
if ERRORLEVEL 1 goto error
exit
:error
echo Could not start service
pause
请建议如何在批处理中使用if else语句并在start函数中传递参数。
答案 0 :(得分:0)
将参数传递给BAT文件:
MyObject.Run("E:\start.bat The_parameter1 The_parameter2");
获取BAT文件中的参数:
echo parameter 1 = %1
echo parameter 2 = %2
在BAT中进行IF ELSE
测试
net start AMAPTestJetty8i0T1
if %ERRORLEVEL%==1 (goto error
) else (
goto NoError)
或使用重定向:
net start AMAPTestJetty8i0T1 && goto NoError || goto Error