|
|
【参加讨论】
vbc /r:system.dll /r:system.windows.forms.dll /r:system.drawing.dll reg01.vb
 图03:用VB.NET创建和修改注册表程序运行界面 | 六.是如何删除注册表信息:
VB.NET删除注册表中的信息也是通过RegistryKey类中封装的方法来实现,具体的说,就是DeleteSubKey ( )方法、DeleteSubKeyTree ( )方法和DeleteValue ( )方法。其中
1). DeleteSubKey ( )方法:
在使用此方法删除一个指定的子键的时候,要确保此子健下面不能存在子健,否则会产生一个错误信息。在程序中调用此方法有二种原型:
I > . DeleteSubKey ( string , subkey ):这种调用方式就是直接删除指定的子健。
II > . DeleteSubKey ( string subkey , Boolean info ):其中的"string"是要删除的子健的名称,"Boolean"参数的意思是:如果值为"True",则在程序调用的时候,删除的子健不存在,则产生一个错误信息;如果值为"False",则在程序调用的时候,删除的子健不存在,也不产生错误信息,程序依然正确运行。所以在具体的程序设计过程中,我还是推荐使用第二种调用方法。
(2). DeleteSubKeyTree ( )方法:
此方法是彻底删除指定的子健目录,即:删除该子健以及该子健以下的全部子健。由于此方法的破坏性是非常强的,所以在使用的时候要非常注意。在程序中调用此方法的原型为:
DeleteSubKeyTree ( string subkey ):其中"subkey"就是要彻底删除的子健名称。
下面这一段代码功能就是删除已经打开子健"A000"下面的子健"ddd":
Dim hklm As RegistryKey = Registry.LocalMachine '打开"SYSTEM"子健 Dim software11 As RegistryKey = hklm.OpenSubKey ( "SYSTEM" ,true ) '打开"A000"子健 Dim software As RegistryKey = software11.OpenSubKey ( "A000" , true ) software.DeleteSubKeyTree ( "ddd" ) |
(3). DeleteValue ( )方法:
此方法是删除指定的健值。在程序中调用此方法的原型为:
DeleteValue ( string value ):其中"value"就是要删除的健值的名称。
下面这一段代码的作用就是删除子健"ddd"中的健"www":
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.OpenSubKey ( "ddd" , true ) ddd.DeleteValue( "www" )
|
七.VB.NET删除注册表信息程序代码(reg02.vb):
通过上面的那个例子,结合以上的知识,我们可以得到用来删除有reg01.vb所创建的注册表信息的程序代码(reg02.vb),代码如下:
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 ) ) '按顺序打开子健www.xker.com(小新技术网) 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 ) software.DeleteSubKeyTree ( "ddd" ) 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.OpenSubKey ( "ddd" , true ) ddd.DeleteValue( "www" ) End Sub
End Class Module Module1 Sub Main ( ) Application.Run ( New Form1 ( ) ) End Sub End Module |
编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部]
上一篇:让注册表记住VFP应用程序的使用次数
下一篇:没有了
转载请注明来源:www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
|
|
|