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

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

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

示例代码如下

     Protected   Sub Button1_Click(ByVal sender As ObjectByVal 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值