虽然html不能直接调用bat脚本,但是可以使用html的application即hta实现。通过添加按钮,可以实现界面化操作,非常方便,界面如下图。
主要功能如下:
1. 实现界面化操作;
2. 点击其中一个按钮,后台调用相应的功能;
3. 点击脚本按钮,bat脚本开始运行;
4. 可点击open按钮,打开脚本文件,直接编辑;
5. hta文件可编辑,根据自己的需求任意添加新按钮,实现新功能。
hta代码实现如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>TOOLS</title>
<style>
<!--
body, table, p, td, div,select { font:menu}
.button {boder:0; HEIGHT: 20px;width:60px;cursor:hand;font:menu}
-->
</style>
</head>
<body>
<SCRIPT language="VBScript">
Sub bat
Const NORMAL_WINDOW=1
Set objShell = CreateObject("Shell.Application")
End Sub
</SCRIPT><p>
<SCRIPT language=JavaScript>
function Run(strPath) {
exe.value=strPath;
try {
var objShell = new ActiveXObject("wscript.shell");
objShell.Run(strPath);
objShell = null;
}
catch (e){alert('Can not get the file"'+strPath+'". Please check the path and file name. ')}
}
</SCRIPT><p>
<br>Please input the exe: <br>
<input name=exe type=text size=21>
<BUTTON style="width: 80px; height: 23px; color: #FFFFFF; background:green;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run(exe.value)">confirm</BUTTON><br>
<BUTTON style="width: 160px; height: 40px; color: #FFFFFF; background:blue;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('calc')">calc</BUTTON><br>
<BUTTON style="width: 160px; height: 40px; color: #FFFFFF; background:blue;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('notepad++.exe')">notepad</BUTTON><br>
<BUTTON style="width: 160px; height: 40px; color: #FFFFFF; background:blue;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('cmd')">cmd</BUTTON><br>
<BUTTON style="width: 160px; height: 40px; color: #FFFFFF; background:blue;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('IEXPLORE.EXE')">IE</BUTTON><br>
<BUTTON style="width: 160px; height: 40px; color: #FFFFFF; background:blue;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('mspaint')">paint</BUTTON><br>
<BUTTON style="width: 160px; height: 40px; color: #FFFFFF; background:blue;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('D:\ui_set_bat\all_bat\tbd.bat')">bat</BUTTON>
<BUTTON style="width: 80px; height: 40px; color: #FFFFFF; background:slategray;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('notepad++.exe D:\ui_set_bat\all_bat\init.bat')">open</BUTTON><br>
<BUTTON style="width: 160px; height: 40px; color: #FFFFFF; background:blue;font-size: 15px;font-weight:bolder;border-radius:6px;" class=button onclick="Run('D:\ui_set_bat\all_bat\all_debug_switch.bat')">Debug_Switch</BUTTON><br>
</body>
</html>
备注:将该文件保存为 *.hta 后缀名,双击运行。