''' <summary>
''' 注册表设置值
''' </summary>
''' <param name="strKey"></param>
''' <param name="strName"></param>
''' <param name="strValue"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function SetRegistry(ByVal strKey As String, ByVal strName As String, ByVal strValue As String) As Boolean
Try
Dim Key_LocalMachine As Microsoft.Win32.RegistryKey
Key_LocalMachine = My.Computer.Registry.LocalMachine 'get the key path of HKEY_LOCAL_MACHINE
Dim Key_Created As Microsoft.Win32.RegistryKey
Key_Created = Key_LocalMachine.OpenSubKey(strKey, True) 'set the true for can write
If Key_Created Is Nothing Then
Key_Created = Key_LocalMachine.CreateSubKey(strKey) 'careat the key
End If
Key_Created.SetValue(strName, strValue) 'set the values of the key
Return True
Catch ex As Exception
Return False
End Try
End Function
''' <summary>
''' 获取注册表值
''' </summary>
''' <param name="strKey"></param>
''' <param name="strName"></param>
''' <param name="strValue"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetValueFromRegistry(ByVal strKey As String, ByVal strName As String, ByRef strValue As String) As Boolean
Try
Dim Key_LocalMachine As Microsoft.Win32.RegistryKey
Key_LocalMachine = My.Computer.Registry.LocalMachine 'get the key path of HKEY_LOCAL_MACHINE
Dim Key_Get As Microsoft.Win32.RegistryKey
Key_Get = Key_LocalMachine.OpenSubKey(strKey)
If Key_Get Is Nothing Then
Return False
End If
strValue = Key_Get.GetValue(strName) 'get the values of the key
Return True
Catch ex As Exception
Return False
End Try
End Function
''' <summary>
''' 判断值是否存在
''' </summary>
''' <param name="strKey"></param>
''' <param name="strName"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function RegistryExist(ByVal strKey As String, ByVal strName As String) As Boolean
Try
Dim Key_LocalMachine As Microsoft.Win32.RegistryKey
Key_LocalMachine = My.Computer.Registry.LocalMachine 'get the key path of HKEY_LOCAL_MACHINE
Dim Key_Exist As Microsoft.Win32.RegistryKey
Key_Exist = Key_LocalMachine.OpenSubKey(strKey, True) 'set the true for can write
If Key_Exist Is Nothing Then
Return False
End If
If Key_Exist.GetValue(strName) Is Nothing Then
Return False
End If
Return True
Catch ex As Exception
Return False
End Try
End Function
''' <summary>
''' 删除注册表对应值
''' </summary>
''' <param name="strKey"></param>
''' <param name="strName"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function DeleteRegistry(ByVal strKey As String, ByVal strName As String) As Boolean
Try
Dim Key_LocalMachine As Microsoft.Win32.RegistryKey
Key_LocalMachine = My.Computer.Registry.LocalMachine 'get the key path of HKEY_LOCAL_MACHINE
Dim Key_Del As Microsoft.Win32.RegistryKey
Key_Del = Key_LocalMachine.OpenSubKey(strKey, True) 'set the true for can write
If Key_Del Is Nothing Then
Return False
End If
Key_Del.DeleteValue(strName) 'delete the values of the key'name
Return True
Catch ex As Exception
Return False
End Try
End Function

调用:

 SetRegistry("SOFTWARE\XXXX\DIS-ESS\FTP", "User", "")
Dim temvalue As String = ""
GetValueFromRegistry("SOFTWARE\XXXX\DIS-ESS\FTP", "User", temvalue) 'DeleteRegistry("SOFTWARE\Unisys\DIS-ESS\FTP", "User") RegistryExist("SOFTWARE\XXXX\DIS-ESS\FTP", "User")

VB.NET 注册表基本操作的更多相关文章

  1. VB的写法,关于版本写入注册表

    VB的写法,关于版本写入注册表   '软件都有一个关于我们的菜单,单单实现这个功能并不难,困难的是能够将这些信息写入注册表中,这样每次只要弹出这样的窗口,就从注册表里去搜索.这样是不是极大的节省了资源 ...

  2. C#操作注册表——读、写、删除、判断等基本操作

    一.引入命名空间: using Microsoft.Win32; 二.创建注册表项:CreateSubKey(name)方法 添加SubKey时候首先要打开一个表项,并设置参数为true,才能成功创建 ...

  3. VB - 修改注册表

    Vbs中修改注册表的语句主要有: 1.读注册表的关键词和值: 可以通过把关键词的完整路径传递给wshshell对象的regread方法.例如: set ws=wscript.createobject( ...

  4. 入侵检测中需要监控的注册表路径研究(Windows Registry Security Check)

    1. Windows注册表简介 注册表(Registry,繁体中文版Windows称之为登录档)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息.早在Wind ...

  5. delphi 注册表操作(读取、添加、删除、修改)完全手册

    DELPHI VS PASCAL(87)  32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...

  6. c# asp.net 鼠标改变控件坐标位置,更改控件坐标,注册表保存读取,打印,查找局域网内打印机等等收集

    界面虽然被我弄的很难看,但功能还可以 里边注册表的路径自己设置一下,或者加一个创建注册表的语句,不然会报错 前台: <%@ Page Language="C#" AutoEv ...

  7. C#读取注册表信息

    注册表是视窗系统的一个核心的数据库,在这个数据库中存放中与系统相关的各种参数,这些参数直接控制中系统的启动.硬件的驱动程序安装信息以及在视窗系统上运行的各种应用程序的注册信息等.这就意味着,如果注册表 ...

  8. 64位WINDOWS系统环境下应用软件开发的兼容性问题(CPU 注册表 目录)

    应用软件开发的64 位WINDOWS 系统环境兼容性 1. 64 位CPU 硬件 目前的64位CPU分为两类:x64和IA64.x64的全称是x86-64,从名字上也可以看出来它和 x86是兼容的,原 ...

  9. Delphi的注册表操作

    转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息.     一.创 ...

随机推荐

  1. <a>标签跳转传值。

    <a href="public_html/app/Tpl/song_1/inc/{url r="deal#support" p="id=$deal_inf ...

  2. 分分钟教会大家第一个Spring入门案例

    1.下载Spring jar包,并添加到项目中. 官网地址http:springsource.org 2.在项目中新建一个类      package cn.test; public class He ...

  3. 百度浏览器+hao123评价

    1.用户界面: 界面比较简洁,没有多余的没用的东西.在界面上部有天气,比较方便用户查看天气,中间有各个实用性网站和大家通常使用较多的网站,可以比较快的查看.侧栏有些比较有针对性的内容.上部还有可以静音 ...

  4. svn 设置post-commit后 报错svn: Can't convert string from 'UTF-8' to native encoding

    文件语言编码和系统冲突导致的错误,设置svn目录下hooks/post-commit加上: export LANG=zh_CN.GB2312 或者: export LANG=zh_CN.UTF-8

  5. [Android分享] 【转帖】Android ListView的A-Z字母排序和过滤搜索功能

      感谢eoe社区的分享   最近看关于Android实现ListView的功能问题,一直都是小伙伴们关心探讨的Android开发问题之一,今天看到有关ListView实现A-Z字母排序和过滤搜索功能 ...

  6. iOS开发——UI基础-懒加载,plist文件,字典转模型,自定义view

    一.懒加载 只有使用到了商品数组才会创建数组 保证数组只会被创建一次 只要能够保证数组在使用时才创建, 并且只会创建一次, 那么我们就称之为懒加载 lazy - (void)viewDidLoad 控 ...

  7. BZOJ3172——[Tjoi2013]单词

    1. 题目大意:一篇论文是由许多单词组成,现在想知道每个单词分别在论文中出现多少次. 2.分析:对着 广义后缀自动机的图看,我们就会发现玄机,答案不就是这个单词下的后缀个数吗? 于是建立自动机,然后求 ...

  8. Java BigDecimal详解

    借用<Effactive Java>这本书中的话,float和double类型的主要设计目标是为了科学计算和工程计算.他们执行二进制浮点运算,这是为了在广域数值范围上提供 较为精确的快速近 ...

  9. Units Problem: How to read text size as custom attr from xml and set it to TextView in java code

    Here is this topic’s background: I defined a custom View which extends FrameLayout and contains a Te ...

  10. 9. JEB 1.5插件编写一

    2.0之后好像新增加了很多API,有所区别 本文采用Java+Eclipse作为开发环境 插件支持的语言  文档: jeb-1.5/doc/index.html 一.Hello World工程 1. ...