2014年11月25日 星期二

VB.Net 的 路徑 在 Schedule Job 與 Command Prompt 差在哪?

執行 這篇 的說明, 得到下面的值.. 紀錄一下.. 否則看xxx 的說明, 也會曲解意思.. 

Schedule Tasks (排程)下的執行結果: 
1.取得和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。 
System.Environment.CurrentDirectory: 
結果:C:\Windows\system32 

2.取得啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。 
System.Windows.Forms.Application.StartupPath: 
結果:D:\EvnPathTest\EvnPathTest\bin\Debug 

3.取得應用程序的當前工作目錄。 
System.IO.Directory.GetCurrentDirectory(): 
結果:C:\Windows\system32 

4.取得當前 Thread 的當前應用程序域的基目錄,它由程序集衝突解決程序用來探測程序集。 
System.AppDomain.CurrentDomain.BaseDirectory: 
結果:D:\EvnPathTest\EvnPathTest\bin\Debug\ 

5.取得和設置包含該應用程序的目錄的名稱。 
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase: 
結果:D:\EvnPathTest\EvnPathTest\bin\Debug\ 

6.取得啟動了應用程序的可執行文件的路徑,包括可執行文件的名稱。 
System.Windows.Forms.Application.ExecutablePath: 
結果:D:\EvnPathTest\EvnPathTest\bin\Debug\EvnPathTest.exe 

7.取得當前執行的exe的文件名。 
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName: 
結果:D:\EvnPathTest\EvnPathTest\bin\Debug\EvnPathTest.exe 

8.取得當前進程的完整路徑,包含文件名。 
Me.GetType().Assembly.Location: 
結果:D:\EvnPathTest\EvnPathTest\bin\Debug\EvnPathTest.exe 


命令提示字元(Command Prompt)下的執行結果: 
1.取得和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。 
System.Environment.CurrentDirectory: 
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug 

2.取得啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。 
System.Windows.Forms.Application.StartupPath: 
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug 

3.取得應用程序的當前工作目錄。 
System.IO.Directory.GetCurrentDirectory(): 
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug 

4.取得當前 Thread 的當前應用程序域的基目錄,它由程序集衝突解決程序用來探測程序集。 
System.AppDomain.CurrentDomain.BaseDirectory:
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug\ 

5.取得和設置包含該應用程序的目錄的名稱。 
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase: 
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug\ 

6.取得啟動了應用程序的可執行文件的路徑,包括可執行文件的名稱。 
System.Windows.Forms.Application.ExecutablePath: 
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug\EvnPathTest.exe 

7.取得當前執行的exe的文件名。 
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName: 
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug\EvnPathTest.exe 

8.取得當前進程的完整路徑,包含文件名。 
Me.GetType().Assembly.Location: 
結果:D:\Work\VBWork\EvnPathTest\EvnPathTest\bin\Debug\EvnPathTest.exe 


由結果來看, 系統排程與手動執行差在 :GetCurrentDirectory 及 CurrentDirectory