我是一个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}
http://www.cnblogs.com/yelsea/archive/2006/09/28/517522.html