问题描述
我正在尝试为客户端创建一个html页面,以便他能够在任何远程桌面上启动或停止特定的窗口服务。总数的范围内的服务是20左右。而不是创建20(开始)+ 20(停止)+ 20(重新启动)批处理文件,我想有1个批处理文件与if if条件,我可以在JavaScript函数中传递参数。代码为html页面如下:
I am trying to create a html page for client from which he'll be able to start or stop a particular window service on any remote desktop. Total no. of services in scope are around 20. Rather than creating 20(start) + 20(stop) + 20(restart) batch file, i want to have 1 batch file with if else condition, I could pass parameter in javascript function. Code for html page is below :
<!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中的代码是:
and code in start.bat is :
@echo off
net start AMAPTestJetty8i0T1
if ERRORLEVEL 1 goto error
exit
:error
echo Could not start service
pause
请建议如何应用if语句批处理并在开始时传递参数功能。
Please suggest how can I apply if else statement in batch and pass parameter in start function.
推荐答案
将参数传递到您的BAT文件:
To pass parameters to your BAT file :
MyObject.Run("E:\start.bat The_parameter1 The_parameter2");
要获取BAT文件中的参数:
To get the parameters in your BAT File :
echo parameter 1 = %1
echo parameter 2 = %2
在BAT中进行 IF ELSE
测试
To make an IF ELSE
test in a BAT
net start AMAPTestJetty8i0T1
if %ERRORLEVEL%==1 (goto error
) else (
goto NoError)
或者使用重定向:
Or using redirection :
net start AMAPTestJetty8i0T1 && goto NoError || goto Error
这篇关于将参数从javascript函数传递到批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!