C#获取各种目录,操作系统版本

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.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章