IE和Firefox下执行exe程序

来源:互联网 发布:数据挖掘就业前景 编辑:程序博客网 时间:2024/04/20 09:22

IE 下执行exe程序 (ActiveX)

  1. <a href="javascript:LaunchApp()">Click here to Execute your file</a>
  2. <script>
  3. function LaunchApp() {
  4. if (!document.all) {
  5. alert ("This ActiveXObject is only available for Internet Explorer");
  6. return;
  7. }

  8. var ws = new ActiveXObject("WScript.Shell");
  9. ws.Exec("D:\\Software\\youfile.exe");
  10. }
  11. </script>

 Firefox 下执行exe程序

  1. <a href="javascript:LaunchApp()">Click here to Execute your file</a>
  2. <script>
  3. functionLaunchApp() {
  4. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
  5. var file=Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  6. file.initWithPath("D:\\Software\\yourfile.exe");
  1. file.launch();
  2. }
  3. </script>

例子:如果exe带参数则var args = ["argument1""argument2"]; 

  1. var file = Components.classes["@mozilla.org/file/local;1"]  
  2.                      .createInstance(Components.interfaces.nsILocalFile);  
  3. file.initWithPath("c:\\myapp.exe");  
  4.   
  5. // create an nsIProcess  
  6. var process = Components.classes["@mozilla.org/process/util;1"]  
  7.                         .createInstance(Components.interfaces.nsIProcess);  
  8. process.init(file);  
  9.   
  10. // Run the process.  
  11. // If first param is true, calling thread will be blocked until  
  12. // called process terminates.  
  13. // Second and third params are used to pass command-line arguments  
  14. // to the process.  
  15. var args = ["argument1""argument2"];  
  16. process.run(false, args, args.length); 
如:var arguments = ["-h","10.20.65.41","-p","5901","-w","11111111","--title","1111"];


积累:
  1. var WSS = new ActiveXObject("WScript.Shell");  
  2. WSS.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device","pdfFactory Pro,winspool,FPP2:");  
             这个需要是来源于客户端设置打印机,并直接通过applet进行打印