VS2005 My.Computer.Registry 对象 操作注册表 简单示例

本例将通过My.Computer.Registry 对象 对注册表的修改
添加一个右键菜单项到IE浏览器
通过该菜单项
调用C:\a.html
效果是弹出一个提示

1.添加Microsoft.VisualBasic.dll引用
2.创建vb页面 编码以实现对注册表的操作

示例代码如下

ExpandedBlockStart.gif ContractedBlock.gif      Protected   Sub Button1_Click() Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click
InBlock.gif
InBlock.gif        
'创建注册表项
InBlock.gif
        'My.Computer.Registry.CurrentUser.CreateSubKey("Software\Microsoft\Internet Explorer\MenuExt\MyTestKey")
InBlock.gif
        '' Change MyTestKeyValue to This is a test value. 
InBlock.gif
        'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", _
InBlock.gif
        '"MyTestKeyValue", "This is a test value.")
InBlock.gif

InBlock.gif        
'确定值是否存在
InBlock.gif
        'If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "MyTestKeyValue", Nothing) Is Nothing Then
InBlock.gif
        '    MsgBox("Sorry,Value does not exist.")
InBlock.gif
        'Else
InBlock.gif
        '    MsgBox("OK,Value exist.")
InBlock.gif
        'End If
InBlock.gif

InBlock.gif        
'读取值
InBlock.gif
        'Dim readValue As String
InBlock.gif
        'readValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "MyTestKeyValue", Nothing)
InBlock.gif
        'MsgBox("The value is :" & readValue)
InBlock.gif

InBlock.gif        
'将值写入注册表项
InBlock.gif
        'a.html 内容
InBlock.gif
        '<script language="javascript" type="text/javascript">
InBlock.gif
        'alert("");
InBlock.gif
        '</script>
InBlock.gif

InBlock.gif        
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "", "C:\a.html")
InBlock.gif

InBlock.gif        
'My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", "Contexts", "1", Microsoft.Win32.RegistryValueKind.DWord)
InBlock.gif

InBlock.gif        
'删除注册表项
InBlock.gif
        'My.Computer.Registry.CurrentUser.DeleteSubKey("Software\Microsoft\Internet Explorer\MenuExt\MyTestKey", False)
InBlock.gif

ExpandedBlockEnd.gif    
End Sub

转载于:https://www.cnblogs.com/freeliver54/archive/2006/12/20/597886.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值