我是一个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}
新闻热点
疑难解答