我是一個c#的初學者,這是我參考一些資料,自己弄的一個通過訪問當前操作系統的注冊表來獲取當前操作系統相關信息的小程序,僅供參考。
 1using system;
 2using system.collections.generic;
 3using system.componentmodel;
 4using system.data;
 5using system.drawing;
 6using system.text;
 7using system.windows.forms;
 8using microsoft.win32;
 9
10namespace reg4u
11{
12    public partial class form1 : form
13    {
14        public form1()
15        {
16            initializecomponent();
17        }
18
19        private void button1_click(object sender, eventargs e)
20        {
21            registrykey rk;
22            rk = registry.localmachine.opensubkey("software//microsoft//windows nt//currentversion");
23            string s= "當前操作系統版本:"+rk.getvalue("productname").tostring();
24            s = s +"/r/n"+rk.getvalue("csdversion").tostring() ;
25            s = s + "/r/n當前操作系統安裝序列號:/r/n" + rk.getvalue("productid").tostring();
26            s = s + "/r/n當前系統版本號:" + rk.getvalue("currentbuildnumber").tostring();
27            rk.close();
28            textbox1.text = textbox1.text+"/r/n"+s;
29        }
30
31        private void form1_load(object sender, eventargs e)
32        {
33            registrykey rk;
34            rk = registry.localmachine.opensubkey("software//microsoft//windows nt//currentversion");
35            string s = rk.getvalue("productname").tostring();
36            if (system.text.regularexpressions.regex.ismatch(s, "windows 2000"))
37            {
38                textbox1.text = "您的操作系統是2k,恭喜您,你的當前系統適合本軟件的使用!";
39            }
40            rk.close();
41        }
42    }
43}
 
  | 
新聞熱點
疑難解答