2011-06-25 50 views
2

我有我要用來啓動已經安裝在我的電腦如NOTEPAD.EXE
問題程序的插件找到一個外部的程序是,它似乎Firefox不搜索系統路徑,程序即使用Firefox運行在系統PATH

 file.initWithPath("c:\\windows\\system32\\notepad.exe");//works 
    //file.initWithPath("notepad.exe");//does not work 
     //file.initWithPath("%systemroot%\\notepad.exe");//does not work 


問:
是否有將Firefox查找系統中的PATH程序的方式嗎?
這裏是我的完整功能

autoStartNotepad:function() 
{ 
    // create an nsILocalFile for the executable 
    var file = Components.classes["@mozilla.org/file/local;1"] 
     .createInstance(Components.interfaces.nsILocalFile); 
    file.initWithPath("notepad.exe");//does not work 
    //but file.initWithPath("c:\\windows\\system32\\notepad.exe");//works 

    // create an nsIProcess 
    var process = Components.classes["@mozilla.org/process/util;1"] 
         .createInstance(Components.interfaces.nsIProcess); 
    process.init(file); 

    // Run the process. 
    // If first param is true, calling thread will be blocked until 
    // called process terminates. 
    // Second and third params are used to pass command-line arguments 
    // to the process. 
    var args = []; 
    process.run(false, args, args.length); 
} 

回答

2

nsIProcess不會做到這一點,只接受完整路徑。你需要看看環境變量自己:

var environment = Components.classes["@mozilla.org/process/environment;1"] 
          .getService(Components.interfaces.nsIEnvironment); 
var path = environment.get("PATH"); 
var root = environment.get("SYSTEMROOT"); 

您可以拆分的PATH變量,並檢查各個目錄,或使用SYSTEMROOT變量的值。

您可以運行cmd.exe /c notepad.exe但在那裏您還需要首先找到cmd.exe