可以使用System.Environment.OSVersion类来得到用户系统环境信息
使用下面的代码就可以做到:
1 class Program
2 {
3 static void Main(string[] args)
4 {
5 OperatingSystem osObj = System.Environment.OSVersion;
6 Console.WriteLine("PlatForm is:{0}", osObj.Platform);
7 Console.WriteLine("Service Pack is:{0}", osObj.ServicePack);
8 Console.WriteLine("Version is:{0}", osObj.Version);
9 Console.WriteLine("VersionString is:{0}", osObj.VersionString);
10 Console.WriteLine("CLR Version is:{0}", System.Environment.Version);
11 Console.ReadKey();
12 }
13 }
14
2 {
3 static void Main(string[] args)
4 {
5 OperatingSystem osObj = System.Environment.OSVersion;
6 Console.WriteLine("PlatForm is:{0}", osObj.Platform);
7 Console.WriteLine("Service Pack is:{0}", osObj.ServicePack);
8 Console.WriteLine("Version is:{0}", osObj.Version);
9 Console.WriteLine("VersionString is:{0}", osObj.VersionString);
10 Console.WriteLine("CLR Version is:{0}", System.Environment.Version);
11 Console.ReadKey();
12 }
13 }
14
需要注意的是,OSVersion类不会直接提供详细的例如“Windows Vista”或者“Windows 7”这样的操作系统品牌,你应该通过相应的系统版本号来代替。