1,獲取各種目錄
//獲取應用程序的當前工作目錄。
String path1 = System.IO.Directory.GetCurrentDirectory();
MessageBox.Show("獲取應用程序的當前工作目錄:" + path1);
//獲取程序的基目錄。
String path2 = System.AppDomain.CurrentDomain.BaseDirectory;
MessageBox.Show("獲取程序的基目錄:" + path2);
//獲取和設置包括該應用程序的目錄的名稱。
String path3 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
MessageBox.Show("獲取和設置包括該應用程序的目錄的名稱:" + path3); /
/獲取啓動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。
String path4 = System.Windows.Forms.Application.StartupPath;
MessageBox.Show("獲取啓動了應用程序的可執行文件的路徑,不包括可執行文件的名稱:" + path4);
//獲取啓動了應用程序的可執行文件的路徑及文件名
String path5 = System.Windows.Forms.Application.ExecutablePath;
MessageBox.Show("獲取啓動了應用程序的可執行文件的路徑及文件名:" + path5);
2,獲取操作系統版本
+-----------------------------------------------------------------------------------------------------------------------------------+
| | Windows | Windows | Windows | Windows NT | Windows | Windows | Windows | Windows |
+-----------------------------------------------------------------------------------------------------------------------------------+
| | 95 | 98 | Me | 4.0 | 2000 | XP | Vista | 7 |
+-----------------------------------------------------------------------------------------------------------------------------------+
| PlatformID | 1 | 1 | 1 | 2 | 2 | 2 | | |
+-----------------------------------------------------------------------------------------------------------------------------------+
| 主版本號 | 4 | 4 | 4 | 4 | 5 | 5 | 6 | 6 |
+-----------------------------------------------------------------------------------------------------------------------------------+
| 副版本號 | 0 | 10 | 90 | 0 | 0 | 1 | 0 | 1 |
+-----------------------------------------------------------------------------------------------------------------------------------+
System.Environment.OSVersion.Version.Major 獲取主版本
System.Environment.OSVersion.Version.Minor 獲取副版本
如
XP 和 2K的Major 都是5, Minor不同,2k對應0,XP對應1.