VS2005 My.Computer.Registry 对象 操作注册表 简单示例
本例将通过My.Computer.Registry 对象 对注册表的修改
添加一个右键菜单项到IE浏览器
通过该菜单项
调用C:\a.html
效果是弹出一个提示
1.添加Microsoft.VisualBasic.dll引用
2.创建vb页面 编码以实现对注册表的操作
示例代码如下
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'创建注册表项
'My.Computer.Registry.CurrentUser.CreateSubKey("Software\Microsoft\Internet Explorer\MenuExt\MyTestKey")
'' Change MyTestKeyValue to This is a test value.
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", _
'"MyTestKeyValue", "This is a test value.")
'确定值是否存在
'If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "MyTestKeyValue", Nothing) Is Nothing Then
' MsgBox("Sorry,Value does not exist.")
'Else
' MsgBox("OK,Value exist.")
'End If
'读取值
'Dim readValue As String
'readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "MyTestKeyValue", Nothing)
'MsgBox("The value is :" & readValue)
'将值写入注册表项
'a.html 内容
'<script language="javascript" type="text/javascript">
'alert("");
'</script>
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "", "C:\a.html")
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "Contexts", "1", Microsoft.Win32.RegistryValueKind.DWord)
'删除注册表项
'My.Computer.Registry.CurrentUser.DeleteSubKey("Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", False)
End Sub
'创建注册表项
'My.Computer.Registry.CurrentUser.CreateSubKey("Software\Microsoft\Internet Explorer\MenuExt\MyTestKey")
'' Change MyTestKeyValue to This is a test value.
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", _
'"MyTestKeyValue", "This is a test value.")
'确定值是否存在
'If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "MyTestKeyValue", Nothing) Is Nothing Then
' MsgBox("Sorry,Value does not exist.")
'Else
' MsgBox("OK,Value exist.")
'End If
'读取值
'Dim readValue As String
'readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "MyTestKeyValue", Nothing)
'MsgBox("The value is :" & readValue)
'将值写入注册表项
'a.html 内容
'<script language="javascript" type="text/javascript">
'alert("");
'</script>
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "", "C:\a.html")
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "Contexts", "1", Microsoft.Win32.RegistryValueKind.DWord)
'删除注册表项
'My.Computer.Registry.CurrentUser.DeleteSubKey("Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", False)
End Sub
posted on 2006-12-20 13:03 freeliver54 阅读(2111) 评论(2) 编辑 收藏 举报