通過控制台程式列印出每種方法的結果
staticvoid main(string
args)
", typeof
(program).assembly.location);
console.writeline(
"");
console.writeline(
"process.getcurrentprocess().mainmodule.filename:\r\n
", process.getcurrentprocess().mainmodule.filename);
console.writeline(
"");
console.writeline(
"environment.currentdirectory:\r\n
", environment.currentdirectory);
console.writeline(
"");
console.writeline(""
console.writeline(
"");
console.writeline(""
console.writeline(
"");
console.read();
}
通過另乙個程式啟動的**
staticvoid main(string
args)
catch
(exception ex)
console.read();
}
通過其他程式啟動的執行結果:
直接執行結果:(注意不是通過點選除錯執行)
c 獲取程式執行路徑
獲取exe路徑 注意,不要使用system.environment.currentdirectory 或system.io.directory.getcurrentdirectory 因為他們代表獲得當前路徑,可以被改變的,例如openfiledialog每換一次目錄就會改變它。獲取當前路徑的父路徑...
C 獲取專案程式及執行路徑的方法
4.在解除安裝程式獲取系統安裝的目錄 system.reflection.assembly curpath system.reflection.assembly.getexecutingassembly string path curpath.location 得到安裝程式類setuplibrary...
C 獲取當前程式執行路徑
獲取當前程序的完整路徑,包含檔名 程序名 string str this.gettype assembly.location result x exe exe檔案所在的目錄 exe檔名 獲取新的 process元件並將其與當前活動的程序關聯的主模組的完整路徑,包含檔名 程序名 string str ...