|
|
【参加讨论】
SetValue (存在的健 ,新的健值)
五.VB.NET是创建并修改注册表信息的程序代码(reg01.vb):
至此我们不难得到用VB.NET创建并修改注册表的程序代码,在下列代码中,有一点要说明,就是在程序中使用了RegistryKey类中定义另外二个属性:SubKeyCount和ValueCount,其中第一个属性是当前子健下面有多少个子健,第二个是当前子健中定义了多少个健。
Imports System Imports System.Drawing Imports System.ComponentModel Imports System.Windows.Forms Imports Microsoft.Win32 '导入程序中使用的名称空间 Public Class Form1 Inherits Form Public Sub New ( ) MyBase.New ( ) '初始化窗体中的各个组件 InitializeComponent ( ) End Sub '清除程序中使用过的各种资源 Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean ) If disposing Then If Not ( components Is Nothing ) Then components.Dispose ( ) End If End If MyBase.Dispose ( disposing ) End Sub Friend WithEvents Button1 As Button Friend WithEvents listBox1 As ListBox Friend WithEvents Button2 As Button Friend WithEvents Button3 As Button
Private components As System.ComponentModel.Container '初始化程序中使用到的组件 Private Sub InitializeComponent ( ) Me.listBox1 = New ListBox ( ) Me.Button1 = New Button ( ) Me.Button2 = New Button ( ) Me.Button3 = New Button ( ) Me.SuspendLayout ( ) Me.listBox1.ItemHeight = 12 Me.listBox1.Location = New Point ( 8 , 24 ) Me.listBox1.Name = "listBox1" Me.listBox1.Size = New Size ( 480 , 292 ) Me.listBox1.TabIndex = 1
...下略
Me.Controls.Add ( Me.listBox1 ) Me.Controls.Add ( Me.Button1 ) Me.Controls.Add ( Me.Button2 ) Me.Controls.Add ( Me.Button3 ) Me.Name = "Form1" Me.Text = "用VB.NET进行注册表编程!" Me.ResumeLayout ( False )
End Sub
Private Sub Button1_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) _ Handles Button1.Click listBox1.Items.Clear ( ) Dim hklm As RegistryKey = Registry.LocalMachine Dim software11 As RegistryKey = hklm.OpenSubKey ( "SYSTEM" ) '打开"SYSTEM"子健 Dim software As RegistryKey = software11.OpenSubKey ( "A000" ) '打开"A000"子健 Dim KeyCount As integer = software.SubKeyCount '获得当前健下面有多少子健 Dim Str ( ) As String = software.GetSubKeyNames ( ) '获得当前健下面所有子健组成的字符串数组 Dim i As integer For i = 0 to KeyCount - 1 listBox1.Items.Add ( Str ( i ) ) Dim sitekey As RegistryKey = software.OpenSubKey ( Str ( i ) ) '按顺序打开子健 Dim Str2 ( ) As String = sitekey.GetValueNames ( ) '获得当前子健下面所有健组成的字符串数组 Dim ValueCount As integer = sitekey.ValueCount '获得当前子健存在多少健值 Dim j As integer For j = 0 to ValueCount - 1 listBox1.Items.Add ( " " + Str2 ( j ) + ": " + sitekey.GetValue ( Str2 ( j ) ) ) '在列表中加入所有子健、健和健值 Next j Next i End Sub '创建子健,并创建一个健并赋值 Private Sub Button2_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) _ Handles Button2.Click listBox1.Items.Clear ( ) Dim hklm As RegistryKey = Registry.LocalMachine '打开"SYSTEM"子健 Dim software11 As RegistryKey = hklm.OpenSubKey ( "SYSTEM" ,true ) '打开"A000"子健 Dim software As RegistryKey = software11.OpenSubKey ( "A000" , true ) Dim ddd As RegistryKey = software.CreateSubKey ( "ddd" ) ddd.SetValue ( "www" , "1234" ) End Sub '重命名一个健的值 Private Sub Button3_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) _ Handles Button3.Click listBox1.Items.Clear ( ) Dim hklm As RegistryKey = Registry.LocalMachine '打开"SYSTEM"子健 Dim software11 As RegistryKey = hklm.OpenSubKey ( "SYSTEM" ,true ) '打开"A000"子健 Dim software As RegistryKey = software11.OpenSubKey ( "A000" , true ) Dim ddd As RegistryKey = software.CreateSubKey ( "ddd" ) ddd.SetValue ( "www" , "aaaa" ) End Sub
End Class Module Module1 Sub Main ( ) Application.Run ( New Form1 ( ) ) End Sub End Module |
经过下列命令编译后,这些可以得到下面界面:
编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部]
上一篇:让注册表记住VFP应用程序的使用次数
下一篇:没有了
转载请注明来源:www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
|
|
|