C# 获取操作系统版本和Service Pack版本的方法

在编写客户端程序的时候往往需要知道软件的运行环境,比如操作系统版本等信息,此类信息可显示在关于界面等位置。便于开发人员获取软件运行的环境信息,软件维护的时候能够节省调试时间。

private string GetOSAndServicePack()
 {
        OperatingSystem os = Environment.OSVersion;
        RegistryKey rk = 
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
        string osText = 
(string)rk.GetValue("ProductName");
        if (string.IsNullOrWhiteSpace(osText))
            osText = os.VersionString;
        else
            osText = osText = String.Format("{0} 
{1}.{2}.{3}",osText,os.Version.Major,os.Version.Minor,os.Version.Build);
        if (!string.IsNullOrWhiteSpace(os.ServicePack))
            osText = String.Format("{0} 
{1}",osText,os.ServicePack);
        return osText;
}

猜你喜欢

转载自www.cnblogs.com/lsy1991/p/10297881.html
今日推荐