VB.NET 注册表基本操作
''' <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 注册表基本操作的更多相关文章
- VB的写法,关于版本写入注册表
VB的写法,关于版本写入注册表 '软件都有一个关于我们的菜单,单单实现这个功能并不难,困难的是能够将这些信息写入注册表中,这样每次只要弹出这样的窗口,就从注册表里去搜索.这样是不是极大的节省了资源 ...
- C#操作注册表——读、写、删除、判断等基本操作
一.引入命名空间: using Microsoft.Win32; 二.创建注册表项:CreateSubKey(name)方法 添加SubKey时候首先要打开一个表项,并设置参数为true,才能成功创建 ...
- VB - 修改注册表
Vbs中修改注册表的语句主要有: 1.读注册表的关键词和值: 可以通过把关键词的完整路径传递给wshshell对象的regread方法.例如: set ws=wscript.createobject( ...
- 入侵检测中需要监控的注册表路径研究(Windows Registry Security Check)
1. Windows注册表简介 注册表(Registry,繁体中文版Windows称之为登录档)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息.早在Wind ...
- delphi 注册表操作(读取、添加、删除、修改)完全手册
DELPHI VS PASCAL(87) 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...
- c# asp.net 鼠标改变控件坐标位置,更改控件坐标,注册表保存读取,打印,查找局域网内打印机等等收集
界面虽然被我弄的很难看,但功能还可以 里边注册表的路径自己设置一下,或者加一个创建注册表的语句,不然会报错 前台: <%@ Page Language="C#" AutoEv ...
- C#读取注册表信息
注册表是视窗系统的一个核心的数据库,在这个数据库中存放中与系统相关的各种参数,这些参数直接控制中系统的启动.硬件的驱动程序安装信息以及在视窗系统上运行的各种应用程序的注册信息等.这就意味着,如果注册表 ...
- 64位WINDOWS系统环境下应用软件开发的兼容性问题(CPU 注册表 目录)
应用软件开发的64 位WINDOWS 系统环境兼容性 1. 64 位CPU 硬件 目前的64位CPU分为两类:x64和IA64.x64的全称是x86-64,从名字上也可以看出来它和 x86是兼容的,原 ...
- Delphi的注册表操作
转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创 ...
随机推荐
- 小心一些,断言可能让你的造成循环引用NSAssert
block和self的相互引用造成的循环引用,想必大家都是明白的.上下面的代码(截取部分) __weak typeof(self) weakSelf = self; self.jsBridgeFunc ...
- JQuery在asp.net中三种ajax传值
1)通过webservice,注意去掉注释[System.Web.Script.Services.ScriptService]这行前的注释 2)通过aspx.cs文件中的静态方法 3)通过aspx文件 ...
- VIM使用学习笔记 : 按键说明
VIM有三种模式: 一般模式 上下左右移动光标,删除字符或删除整行,复制粘贴 编辑模式 i I i O a A r R 进入编辑模式 命令模式 在一般模式种输入 : / ?,可 ...
- wp手机 htc x310e
入手htc x310e 手机不错,用着流畅 不习惯,已升到wp7.8,系统限制还是有些需要的功能没有,比如说短信拦截什么的 我需要的常用软件少 转手了 1 注销windows live? 设置--应用 ...
- javax.swing.JList 设置分割线
public class TestJList extends JFrame { public TestJList() { JList list = new JList(new String[] { & ...
- ios中二维码的使用之一: 二维码的生成
iOS在7之后,具备了原生的二维码生成API; 生成二维码的准备: #import <CoreImage/CoreImage.h> 导入框架: 开始生成: //1- 创建过滤器 CIFi ...
- Spatial pyramid pooling (SPP)-net (空间金字塔池化)笔记(转)
在学习r-cnn系列时,一直看到SPP-net的身影,许多有疑问的地方在这篇论文里找到了答案. 论文:Spatial Pyramid Pooling in Deep Convolutional Net ...
- Linux的后台执行进程之nohup
nohup 用途:LINUX命令用法,不挂断地运行命令. 语法:nohup Command [ Arg ... ] [ & ] 描述:nohup 命令运行由 Command 参数和任何相关 ...
- minigui交叉编译整理
简介 MiniGUI 是一款面向嵌入式系统的高级窗口系统(Windowing System)和图形用户界面(Graphical User Interface,GUI)支持系统,由魏永明先生于 1998 ...
- SQL Sever2008r2 数据库服务各种无法启动的解决办法
一.Sql Server服务远程过程调用失败解决 以前出现过这个问题,那时候是因为把实例安装在了D盘,后来D盘被格式化了.然后,这些就没了.今天早上打开电脑,竟然又出现这个问题,可是Server200 ...