2015-09-27 126 views
-2

我正在尝试为客户端创建一个html页面,从中他将能够在任何远程桌面上启动或停止特定的窗口服务。总数的范围内的服务是20左右。而不是创建20(开始)+ 20(停止)+ 20(重新启动)批处理文件,我想有1个批处理文件与if if条件,我可以在JavaScript函数中传递参数。代码的html页面低于:从javascript函数传递参数到批处理文件

<!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 

请建议我怎么能适用,如果在批量else语句,并传递启动功能参数。

回答

0

将参数传递给您的BAT文件:

MyObject.Run("E:\start.bat The_parameter1 The_parameter2"); 

为了让您的BAT文件中的参数:

echo parameter 1 = %1 
echo parameter 2 = %2 

若要使IF ELSE测试在BAT

net start AMAPTestJetty8i0T1 
if %ERRORLEVEL%==1 (goto error 
    ) else (
goto NoError) 

或使用重定向:

net start AMAPTestJetty8i0T1 && goto NoError || goto Error 
+1

“重定向”可能是一个令人困惑的术语,因为您正在使用它;我会称之为“条件命令分隔符”... – aschipfl

+0

对于你使用“条件命令分隔符”是什么?要重定向..... – SachaDee

+0

“重定向”就像'echo text> file.log'; '&&'和'||'是完全不同的东西...... – aschipfl

相关问题