vb.net 注册表删除操作 郁闷中……这不是废话吗vb.net删除注册表,DeleteSubKey只能删除调用实例vb.net删除注册表的子项vb.net删除注册表,并不能直接删除子子项 。
删除注册表项里的所有键值(除了指定一个)外,怎么写?易语言编程建议你使用VB.NET(VS2005 版本),操作注册表非常容易:For Each name As String In My.Computer.Registry.LocalMachine.OpenSubKey("software\microsoft\windows\currentversion\run").GetValueNames
If (name"1425") Then
My.Computer.Registry.LocalMachine.OpenSubKey("software\microsoft\windows\currentversion\run").DeleteValue(name)
End If
Next
vb 对注册表的操作,详细解说赫赫,拿来主义
将下面代码保存为CLS文件,然后在工程中引用就可以了 。
Attribute VB_Name = "BasRegisty"
Option Explicit
'读写注册表任何地方的函数
' 用法见下面
' 摘自杨光宏 (VB技巧手册)
'用于操作注册表的API函数定义 -begin-
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
'用于操作注册表的API函数定义 -end-
'用于操作注册表的常数定义 -begin-
'预定义的根结点
Public Const HKEY_CLASSES_ROOT = H80000000
Public Const HKEY_CURRENT_CONFIG = H80000005
Public Const HKEY_CURRENT_USER = H80000001
Public Const HKEY_DYN_DATA = https://www.04ip.com/post/H80000006
Public Const HKEY_LOCAL_MACHINE = H80000002
Public Const HKEY_PERFORMANCE_DATA = https://www.04ip.com/post/H80000004
Public Const HKEY_USERS = H80000003
'预定义的键值类型
Public Const REG_NONE = 0
Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const REG_DWORD_LITTLE_ENDIAN = 4
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_LINK = 6
Public Const REG_MULTI_SZ = 7
Public Const REG_RESOURCE_LIST = 8
Public Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Public Const REG_RESOURCE_REQUIREMENTS_LIST = 10
#If WinNT Then
'打开注册文件的方式
Public Const KEY_EVENT = H1
Public Const KEY_NOTIFY = H10
Public Const KEY_QUERY_VALUE = https://www.04ip.com/post/H1
Public Const KEY_SET_VALUE = https://www.04ip.com/post/H2
Public Const KEY_CREATE_SUB_KEY = H4
Public Const KEY_ENUMERATE_SUB_KEYS = H8
Public Const KEY_CREATE_LINK = H20
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const KEY_EXECUTE = (KEY_READ)
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
#End If
'注册文件错误描述
Const ERROR_SUCCESS = 0
Const ERROR_BADDB = 1009
Const ERROR_BADKEY = 1010
Const ERROR_CANTOPEN = 1011
Const ERROR_CANTREAD = 1012
Const ERROR_CANTWRITE = 1013
Const ERROR_REGISTRY_RECOVERED = 1014
Const ERROR_REGISTRY_CORRUPT = 1015
Const ERROR_REGISTRY_IO_FAILED = 1016
Const ERROR_NOT_REGISTRY_FILE = 1017
Const ERROR_KEY_DELETED = 1018
Const ERROR_NO_LOG_SPACE = 1019
Const ERROR_KEY_HAS_CHILDREN = 1020
Const ERROR_CHILD_MUST_BE_VOLATILE = 1021
Const ERROR_RXACT_INVALID_STATE = 1369
' 自定义注册文件错误
Const REGAGENT_NOKEY = -1002
Const REGAGENT_NOSUBKEY = -1003
Public glStatus As Long
'用于操作注册表的常数定义 -end-
Function gfsGetKeyStringValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String) As String
'功 能:从注册表中取得串值
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' 输出: gfsGetKeyStringValue String 取得的注册表串值
' 影响: glStatus Long 状态值
Dim llKeyID As Long '打开键的ID
Dim llBufferSize As Long '需读取串的串值长度
Dim lsKeyValue As String '存放读取的串值
'预先置为空
gfsGetKeyStringValue = https://www.04ip.com/post/Empty
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置(子键未设置则读默认值)
glStatus = REGAGENT_NOKEY
Exit Function
End If
'首先打开主键
glStatus = RegOpenKey(plKey, psKey, llKeyID)
If glStatus = ERROR_SUCCESS Then '成功则取需读取字串的串值大小
glStatus = RegQueryValueEx(llKeyID, psSubKey, 0, REG_SZ, 0, llBufferSize)
If llBufferSize2 Then '空值
glStatus = RegCloseKey(llKeyID)
Else '有值,正式读取串值
lsKeyValue = https://www.04ip.com/post/String(llBufferSize1," ")
glStatus = RegQueryValueEx(llKeyID, psSubKey, 0, REG_SZ, ByVal lsKeyValue, llBufferSize)
If glStatus = ERROR_SUCCESS Then
gfsGetKeyStringValue = https://www.04ip.com/post/Left$(lsKeyValue, llBufferSize - 1)
End If
glStatus = RegCloseKey(llKeyID)
End If
End If
End Function
Function gflGetKeyBinaryValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String) As Long
'功 能:从注册表中取得二进制值
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' 输出: gflGetKeyBinaryValue Long 取得的注册表二进制值
' 影响: glStatus Long 状态值
Dim llKeyID As Long '打开键的ID
Dim llKeyValue As Long '存放读取的二进制值
'预先置为空
gflGetKeyBinaryValue = https://www.04ip.com/post/Empty
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置(子键未设置则读默认值)
glStatus = REGAGENT_NOKEY
Exit Function
End If
'首先打开主键
glStatus = RegOpenKey(plKey, psKey, llKeyID)
If glStatus = ERROR_SUCCESS Then '成功则取二进制值
glStatus = RegQueryValueEx(llKeyID, psSubKey, 0, REG_BINARY, llKeyValue, Len(llKeyValue))
If glStatus = ERROR_SUCCESS Then
gflGetKeyBinaryValue = https://www.04ip.com/post/llKeyValue
End If
glStatus = RegCloseKey(llKeyID)
End If
End Function
Function gflGetKeyDwordValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String) As Long
'ok
'功 能:从注册表中取得双字值
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' 输出: gflGetKeyDwordValue Long 取得的注册表双字值
' 影响: glStatus Long 状态值
Dim llKeyID As Long '打开键的ID
Dim llKeyValue As Long '存放读取的双字值
'预先置为空
gflGetKeyDwordValue = https://www.04ip.com/post/Empty
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置(子键未设置则读默认值)
glStatus = REGAGENT_NOKEY
Exit Function
End If
'首先打开主键
glStatus = RegOpenKey(plKey, psKey, llKeyID)
If glStatus = ERROR_SUCCESS Then '成功则取双字值
glStatus = RegQueryValueEx(llKeyID, psSubKey, 0, REG_DWORD, llKeyValue, Len(llKeyValue))
If glStatus = ERROR_SUCCESS Then
gflGetKeyDwordValue = https://www.04ip.com/post/llKeyValue
End If
glStatus = RegCloseKey(llKeyID)
End If
End Function
Sub gpvSetKeyStringValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String, ByVal psKeyValue As String)
'ok
'功 能:设置注册表中的串值
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' psKeyValue String 要设置的串值
' 输出: 无
' 影响: glStatus Long 状态值
Dim llKeyID As Long '打开键的ID
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置(子键未设置则读默认值)
glStatus = REGAGENT_NOKEY
Exit Sub
End If
'首先打开主键
glStatus = RegOpenKey(plKey, psKey, llKeyID)
If glStatus = ERROR_SUCCESS Then '成功则设置值
If Len(psKeyValue) = 0 Then '设为空值
glStatus = RegSetValueEx(llKeyID, psSubKey, 0, REG_SZ, 0, 0)
Else '设为正常值
glStatus = RegSetValueEx(llKeyID, psSubKey, 0, REG_SZ, ByVal psKeyValue, Len(psKeyValue)1)
End If
glStatus = RegCloseKey(llKeyID)
End If
End Sub
Sub gpvSetKeyDwordValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String, ByVal plKeyValue As Long)
'ok
'功 能:设置注册表中的双字值
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' plKeyValue Long 要设置双字值
' 输出: 无
' 影响: glStatus Long 状态值
Dim llKeyID As Long '打开键的ID
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置(子键未设置则读默认值)
glStatus = REGAGENT_NOKEY
Exit Sub
End If
'首先打开主键
glStatus = RegOpenKey(plKey, psKey, llKeyID)
If glStatus = ERROR_SUCCESS Then '成功则设置值
glStatus = RegSetValueEx(llKeyID, psSubKey, 0, REG_DWORD, plKeyValue, Len(plKeyValue))
glStatus = RegCloseKey(llKeyID)
End If
End Sub
Sub gpvSetKeyBinaryValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String, ByVal plKeyValue As Long)
'ok
'功 能:设置注册表中的二进制值
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' plKeyValue Long 要设置的二进制值
' 输出: 无
' 影响: glStatus Long 状态值
Dim llKeyID As Long '打开键的ID
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置(子键未设置则读默认值)
glStatus = REGAGENT_NOKEY
Exit Sub
End If
'首先打开主键
glStatus = RegOpenKey(plKey, psKey, llKeyID)
If glStatus = ERROR_SUCCESS Then '成功则设置值
glStatus = RegSetValueEx(llKeyID, psSubKey, 0, REG_BINARY, plKeyValue, Len(plKeyValue))
glStatus = RegCloseKey(llKeyID)
End If
End Sub
Function gflCreateKey(ByVal plKey As Long, ByVal psKey As String) As Long
'ok
'功 能:创建注册表中的主键
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' 输出: gflCreateKey Long 创建的主键ID
' 影响: glStatus Long 状态值
Dim llKeyID As Long '键ID
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置
glStatus = REGAGENT_NOKEY
Exit Function
End If
'创建主键
glStatus = RegCreateKey(plKey, psKey, llKeyID)
If glStatus = ERROR_SUCCESS Then
gflCreateKey = llKeyID
End If
End Function
Sub gpvDeleteKey(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String)
'ok
'功 能:删除注册表中的主键
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' 输出: 无
' 影响: glStatus Long 状态值
Dim llKeyID As Long '键ID
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置
glStatus = REGAGENT_NOKEY
Exit Sub
End If
'利用创建主键判断是否存在主键
glStatus = RegCreateKey(plKey, psKey, llKeyID)
glStatus = RegDeleteKey(llKeyID, ByVal psSubKey)
End Sub
Sub gpvDeleteKeyValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String)
'ok
'功 能:删除注册表中的键值
'参 数:
' 输入: plKey Long 根键名
' psKey String 主键名
' psSubKey String 子键名
' 输出: 无
' 影响: glStatus Long 状态值
Dim llKeyID As Long '键ID
glStatus = ERROR_SUCCESS '假设成功
'确定参数有效
If Len(psKey) = 0 Then '主键未设置
glStatus = REGAGENT_NOKEY
Exit Sub
End If
'利用创建主键判断是否存在主键
glStatus = RegCreateKey(plKey, psKey, llKeyID)
glStatus = RegDeleteValue(llKeyID, ByVal psSubKey)
End Sub
'Function gfsGetKeyStringValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String) As String
'功 能:从注册表中取得串值
'Function gflGetKeyBinaryValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String) As Long
'功 能:从注册表中取得二进制值
'Function gflGetKeyDwordValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String) As Long
'功 能:从注册表中取得双字值
'Sub gpvSetKeyStringValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String, ByVal psKeyValue As String)
'功 能:设置注册表中的串值
'Sub gpvSetKeyDwordValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String, ByVal plKeyValue As Long)
'功 能:设置注册表中的双字值
'Sub gpvSetKeyBinaryValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String, ByVal plKeyValue As Long)
'功 能:设置注册表中的二进制值
'Function gflCreateKey(ByVal plKey As Long, ByVal psKey As String) As Long
'功 能:创建注册表中的主键
'Sub gpvDeleteKey(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String)
'功 能:删除注册表中的主键
'Sub gpvDeleteKeyValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String)
'功 能:删除注册表中的键值
VB.net注册表操作问题最简单的办法就是用shell
语句
添加和创建注册表项
shell
"cmd
/c
reg
add
hklm\software\myco
/v
data
/t
reg_binary
/d
fe340ead"
删除注册表项
shell
"cmd
/c
reg
delete
hklm\software\myco\myapp\timeout"
删除注册表项
timeout
及其所有子项和值
具体语法请在cmd中输入
reg/?
VB.NET如何删除注册表请使用VB.NET的“My”功能:'添加
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue("running", "C:\myapp.exe")' 删除
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue("running")
【vb.net删除注册表 vbs删除注册表值】关于vb.net删除注册表和vbs删除注册表值的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- 美国代理服务器租,美国代理服务器和端口
- 创维h5怎么用u盘装软件,创维h5m
- 模拟人生橙光游戏攻略,模拟人生攻略橙光完整版
- 设虚拟主机,架设虚拟主机
- mysql新版本怎么使用 mysql最新版本8016
- 新媒体如何制作标题文案,新媒体如何制作标题文案范文
- 电脑怎么重做系统做系统,怎么电脑重新做系统
- 厦门中小企业如何营销,厦门中小企业服务中心
- python函数做值 python数值函数