使用HTML按钮运行.bat文件

3

我正在尝试创建一个按钮,以便更容易地让每个人访问并执行批处理文件。

<input type="button" value="Test" onclick="window.open('bat:///\\123.hello.net\FileShares\ Logon\SAPfileConfig.bat')" />

每当我在IE上执行时,它都会显示找不到文件的错误。
我可能做错了什么?

你的批处理文件在哪个位置? - Hackoo
嗨,Hackoo,它在共享驱动器上的一个文件夹中! - Kim
什么是UNC路径?我不认为它像这样:bat:/// - Hackoo
抱歉,那是我的错误,我本意是要写文件名:但是UNC路径应该是\123.hello.net\FileShares\Logon\Config.bat。 - Kim
2个回答

4
您将无法使用网页执行.bat文件。您可能能够使其自动下载,但由于某些安全问题,它不会被自动执行。

嗨,Nikhil!这不是来自网页,而是来自我们共享驱动器中的文件,我已经出于安全目的对其进行了重命名。 - Kim
1
在这种情况下,它类似于从网站加载,您将无法执行它。如果我的回答对您有用,请接受并赞同我的回答。谢谢。 - NIKHIL NEDIYODATH

2
您可以尝试使用类似以下的 HTA 文件:使用 JavaScript 和 HTA 运行 .exe 或批处理文件。 Javascript_Execute.hta
<html>
<head>
<title>Run Exe or Batch files with Javascript and HTA</title>
<HTA:APPLICATION
  APPLICATIONNAME="Run Exe or Batch files with Javascript and HTA"
  ID="MyHTMLapplication"
  VERSION="1.0"/>
</head>
<script language="Javascript">
function RunMe(){
    var shell = new ActiveXObject("WScript.Shell");
    var path = '"file:\\\\123.hello.net\\FileShares\\Logon\\SAPfileConfig.bat"';
    shell.run(path,1,false);
}
</script>
<input style="width: 170px; height:23px; color: white; background-color: #203040; 
font-family:Book Antiqua;" type="button" Value="Execute Batch File" onClick="RunMe();"
</html>

您可以使用Vbscript和HTA运行Exe或批处理文件:

Vbscript_Execute.hta

<html>
<head>
<title>Run Exe or Batch files with Vbscript and HTA</title>
<HTA:APPLICATION
  APPLICATIONNAME="Run Exe or Batch files with Vbscript and HTA"
  ID="MyHTMLapplication"
  VERSION="1.0"/>
</head>
<script language="Vbscript">
Function RunMe()
Dim Shell,path
Set shell = CreateObject("WScript.Shell")
path = "file:\\123.hello.net\FileShares\Logon\SAPfileConfig.bat"
shell.run path,1,false
End Function
</script>
<input style="width: 170px; height:23px; color: white; background-color: #203040; 
font-family:Book Antiqua;" type="button" Value="Execute Batch File" onClick="RunMe()"
</html>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接