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对象来存取注册表文件中的信息. 一.创 ...
随机推荐
- 2013长沙邀请赛A So Easy!(矩阵快速幂,共轭)
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Cotex-M3内核STM32F10XX系列时钟及其配置方法
一.背景 最近做个项目,需要使用STM32,还是以前一样的观点,时钟就是MCU心脏,供血即时钟频率输出,想要弄明白一个MCU,时钟是一个非常好的切入点.言归正传,网上已经有太多大神详述过STM32的详 ...
- hdu1026.Ignatius and the Princess I(bfs + 优先队列)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- mongoDB--1 概念
1.结构 (1)关系型数据库,数据库,对应mongo中的,数据库 (2)关系型数据库,表,对应mongo中的,集合 (3)关系型数据库,一条记录,对应mongo中的,一个文档(是一条json结构的数据 ...
- C\C++ sizeof 陷阱&&总结
今天使用动态数组,本来想通过sizeof 获取动态数据,结果出现了错误. 先对自己做个测试,能做出下面这个题目,并做出合理解释,可以不用往下看了. ][]; cout<< cout< ...
- Nginx初学者指南
Starting, Stopping, and Reloading Configuration To start nginx, run the executable file. Once nginx ...
- Linux学习:用yum安装php,httpd,mysql
见鸟哥的linux私房菜电子版832页.
- unity3d教程游戏包含的一切文件导入资源
http://www.58player.com/blog-2327-954.html 导入资源 将文件增加至工程文件夹的资源 (Assets) 文件夹后,Unity 将自动检测文件.将任何资源 (As ...
- linux 文件系统sysvinit 流程分析
参考网上许多的教程. 然后有一下相关的笔记: kernel 在挂载完文件系统后,会执行第一个进程init 这个进程的PID为1 这个进程是所有进程的父进程 init 进程,首先要去读取inittab中 ...
- Java中如何解决double和float精度不准的问题
我们知道浮点数是无法在计算机中准确表示的,例如0.1在计算机中只是表示成了一个近似值,因此,对付点数的运算时结果具有不可预知性. 在进行数字运算时,如果有double或float类型的浮点数参与计算, ...