2010-03-22 84 views

回答

9

既然你已經明確要求爲.exe,那麼你可以使用nsILocalFile.launch()https://developer.mozilla.org/en/Code_snippets/Running_applications

var file = Components.classes["@mozilla.org/file/local;1"] 
        .createInstance(Components.interfaces.nsILocalFile); 
file.initWithPath("c:\\myapp.exe"); 
file.launch(); 

如果你想讓它跨平臺的,你應該看看nsIProcess

+0

您不應該只是粘貼一個鏈接,而是總結內容。如果將來鏈接斷開,您的整個答案就不再有任何價值。 – McK 2016-06-02 10:29:29

+0

@McK你是絕對正確的。 – pawel 2016-06-02 10:58:34

+0

'Components.classes'無法通過運行在網頁上的JavaScript訪問,只能通過運行在Firefox擴展中的JavaScript訪問 – NPE 2016-10-25 02:47:17

0

大家好這些誰試圖在Mozilla Firefox中使用JavaScript調用一個exe文件。按照步驟..我可以從我的網站運行EXE。

第1步。在地址欄中輸入「about:config」並將「signed.applets.codebase-principal-support」設置爲true。 第2步。使用此代碼。

<html> 
<head> 
</head> 
<body> 
<p/><input type="button" width="15" value="Run Exe" onclick="RunExe();"/></input></p> 

<script type="text/javascript"> 
function RunExe() 
{ 
alert("In fun RunExe().."); 
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
alert("Done"); 

var exe = window.Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile); 
exe.initWithPath("c:\\WINDOWS\\notepad.exe"); 
alert("exe"); 
var run = window.Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess); 
run.init(exe); 
var parameters = [""]; 
run.run(false, parameters,parameters.length); 
alert("in function RunBat"); 

} 
</script> 
</body> 
</html> 
+0

這不會讓任何網頁調用任意可執行文件嗎? – daveloyall 2014-11-05 15:18:24

相關問題