学习电脑,计算机系统故障维护,电脑技术,电脑知识学习-就上第二电脑网
当前位置: 首页 > 电脑知识 > 电脑基础

如何关闭电脑的端口C# 读取Windows注册表信息

 更新时间: 2019-09-15 13:53:36   作者:第二电脑网   来源:第二电脑网   浏览数:268   我要评论

注册表是视窗系统的一个核心的数据库,在这个数据库中存放中与系统相关的各种参数,这些参数直接控制中系统的启动、硬件的驱动程序安装信息以及在视窗系统上运行的各种应用程序

using System.ComponentModel ;

using System.Windows.Forms ;

using System.Data ;

using Microsoft.Win32 ;

public class Form1 : Form

{

private System.ComponentModel.Container components ;

private ListBox listBox1 ;

private Button button1 ;

public Form1 ( )

{

InitializeComponent ( ) ;

}

//清除在程序中使用过的资源

public override void Dispose ( )

{

base.Dispose ( ) ;

components.Dispose ( ) ;

}

//初始化程序中使用到的组件

private void InitializeComponent ( )

{

this.components = new System.ComponentModel.Container ( ) ;

this.button1 = new Button ( ) ;

this.listBox1 = new ListBox ( ) ;

button1.Location = new System.Drawing.Point ( 16 , 320 ) ;

button1.Size = new System.Drawing.Size ( 75 , 23 ) ;

button1.TabIndex = 0 ;

button1.Text = "读取注册表" ;

button1.Click += new System.EventHandler( this.button1_Click ) ;

listBox1.Location = new System.Drawing.Point ( 16 , 32 ) ;

listBox1.Size = new System.Drawing.Size ( 496 , 264 ) ;

listBox1.TabIndex = 1 ;

this.Text = "读取主测表信息" ;

this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;

this.ClientSize = new System.Drawing.Size ( 528 , 357 ) ;

this.Controls.Add( this.listBox1 ) ;

this.Controls.Add ( this.button1 ) ;

}

//

protected void button1_Click ( object sender , System.EventArgs e )

{

listBox1.Items.Clear ( ) ;

RegistryKey hklm = Registry.LocalMachine ;

RegistryKey software = hklm.OpenSubKey ( "SYSTEM" ) ;

//打开"SYSTEM"子键

RegistryKey no1 = software.OpenSubKey ( "001" ) ;

//打开"001"子键

RegistryKey no2 = no1.OpenSubKey ( "002" ) ;

//打开"002"子键

foreach ( string site in no2.GetSubKeyNames ( ) )

//开始遍历由子键名称组成的字符串数组

{

listBox1.Items.Add ( site ) ;

//在列表中加入子键名称

RegistryKey sitekey = no2.OpenSubKey ( site ) ;

//打开此子键

foreach ( string sValName in sitekey.GetValueNames ( ) )

//开始遍历由指定子键拥有的键值名称组成的字符串数组

{

listBox1.Items.Add ( "" + sValName + ": " + sitekey.GetValue ( sValName ) ) ;

//在列表中加入键名称和对应的键值

}

}

}

//

public static void Main ( )

{

Application.Run ( new Form1 ( ) ) ;

}

}

用C#读取注册表中的注册信息是通过名称空间Micorsoft.Win32中的二个类来实现的。在这二个类中还定义了对注册表信息的删除、修改和重命名的一些方法。这些方法比起本文介绍的读取方法、打开方法来说,更具有破坏性,但也更实用。由于注册表在视窗系统中的重要作用,所以在每一次对注册表进行操作之前,一定要备份,在操作的时候也要非常小心,因为一次的误操作都可能导致系统崩溃。


更多:如何关闭电脑的端口C# 读取Windows注册表信息
https://www.002pc.com/diannaojichu/1017.html

你可能感兴趣的注册表,C#,Windows,读取,信息

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

  浙ICP备140365454号

©CopyRight 2008-2020 002pc.COM Inc All Rights Reserved. 第二电脑网 版权所有 联系QQ:282523118