測試文字功能,小工具,標題

記錄很重要,不然會浪費很多時間在找以前的記憶

一個人的氣度,決定他未來的高度。

2016年3月20日 星期日

C# 查詢作業系統版號

C# 查詢作業系統版號


            System.OperatingSystem osInfo = System.Environment.OSVersion;
            string osver = string.Empty;
 
            //osver += "作業系統 Platform : " + osInfo.Platform.ToString() + "\r\n";
            //osver += "ServicePack : " + osInfo.ServicePack.ToString() + "\r\n";
            //osver += "版本 Version : " + osInfo.Version.ToString() + "\r\n";
            //osver += "Version.Build : " + osInfo.Version.Build + "\r\n";
            //osver += "主要版本 Version.Major : " + osInfo.Version.Major + "\r\n";
            //osver += "Version.MajorRevision : " + osInfo.Version.MajorRevision + "\r\n";
            //osver += "次要版本 Version.Minor : " + osInfo.Version.Minor + "\r\n";
            //osver += "Version.MinorRevision : " + osInfo.Version.MinorRevision + "\r\n";
            //osver += "Version.Revision : " + osInfo.Version.Revision + "\r\n";
            //osver += "VersionString : " + osInfo.VersionString.ToString() + "\r\n";

            switch (osInfo.Version.Major)
            {
                case 5:
                    osver = "Windows XP";
                    break;
                case 6:
                    switch (osInfo.Version.Minor)
                    {
                        case 0:
                            osver = "Windows Vista";
                            break;
                        case 1:
                            osver = "Windows 7";//2008同一版號
                            break;
                        case 2:
                            osver = "Windows 8"; //2012同一版號
                            break;
                    }
                    break;
            };
            MessageBox.Show(osver);

===========================================================

補充:
w7跟2008會出現同一個版號,後來想到可以進regedit查看,配合  Registry.SetValue 就能抓到要的值了

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"CurrentVersion"="6.1"
"CurrentBuild"="7601"
"SoftwareType"="System"
"CurrentType"="Multiprocessor Free"
"InstallDate"=dword:5537557f
"RegisteredOrganization"=""
"RegisteredOwner"="winxp"
"SystemRoot"="C:\\Windows"
"InstallationType"="Client"
"EditionID"="Professional"
"ProductName"="Windows 7 Professional" //這裡抓的到要的名稱
"ProductId"="00xxx-OEM-8992671-xxxxx" //這個xxx是改過的哦

沒有留言:

張貼留言