我是一個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("SoftwareMicrosoftWindows NTCurrentVersion");
23 string s= "當前作業系統版本:" rk.GetValue("ProdUCtName").ToString();
24 s = s "rn" rk.GetValue("CSDVersion").ToString() ;
25 s = s "rn當前作業系統安裝序號:rn" rk.GetValue("ProductId").ToString();
26 s = s "rn當前系統版本號碼:" rk.GetValue("CurrentBuildNumber").ToString();
27 rk.Close();
28 textBox1.Text = textBox1.Text "rn" s;
29 }
30
31 private void Form1_Load(object sender, EventArgs e)
32 {
33 RegistryKey rk;
34 rk = Registry.LocalMachine.OpenSubKey("SoftwareMicrosoftWindows NTCurrentVersion");
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}