轉自:http://www.cnblogs.com/Fly-sky/archive/2009/02/12/1388846.html
這是我參考一些資料,一個通過訪問當前操作系統的注冊表來獲取當前操作系統相關信息的小程序,僅供參考。
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}
獲取本機IP,機器名,然后是操作系統版本
string hostname = System.Net.Dns.GetHostName();
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostname);
dr["NodeIP"] = ipEntry.AddressList[0].ToString();
dr["NodeName"] = hostname;
dr["NodeOSDesc"] = System.Environment.OSVersion.VersionString;