注册表键是什么
看一个程序的源代码时
在注释里有这样的字句:打开的注册表键句柄 临时存储一个注册表键值 打开注册表键
请问注册表健是什么?这些句子的含义是什么?
问题点数:50、回复次数:4Top
1 楼holydiablo(香菜鱼头)回复于 2002-10-24 14:32:41 得分 50
注册表是微软的一个法宝,其正常作用是用来记录系统使用的信息(包括系统的设置、应用程序的设置、文件关联、用户信息等等),因为这个表的很多信息在系统启动的时候就会加载到内存中,所以速度很快(这也就是为什么机器启动慢就会有人告诉你你的注册表太大了,该清理清理之类的话)
平常我们使用的很多工具,超级兔子等等系统设置类的工具很多都是去修改注册表来生效的
Top
2 楼holydiablo(香菜鱼头)回复于 2002-10-24 14:34:18 得分 0
注册表分成6个主键,分别用来存储不同的信息,每个主键又可以继续分下去,就象目录一样是一个树结构Top
3 楼bigwind(大风)回复于 2002-10-24 14:46:44 得分 0
那三句话能不能解释一下?
写注册表的细节是系统规定的,还是程序可以给出的?比如路径阿、信息之类的?
可以读出的吗?Top
4 楼holydiablo(香菜鱼头)回复于 2002-10-24 14:55:37 得分 0
有专门的API进行读写,以下是一个模块
'这是一个操作注册表的Bas文件,其中包含可以建立新键值,删除
'键值,查询键值的函数.
Option Explicit
Global Const REG_SZ As Long = 1
Global Const REG_DWORD As Long = 4
Global Const HKEY_CLASSES_ROOT = &H80000000
Global Const HKEY_CURRENT_USER = &H80000001
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const HKEY_USERS = &H80000003
Global Const ERROR_NONE = 0
Global Const ERROR_BADDB = 1
Global Const ERROR_BADKEY = 2
Global Const ERROR_CANTOPEN = 3
Global Const ERROR_CANTREAD = 4
Global Const ERROR_CANTWRITE = 5
Global Const ERROR_OUTOFMEMORY = 6
Global Const ERROR_INVALID_PARAMETER = 7
Global Const ERROR_ACCESS_DENIED = 8
Global Const ERROR_INVALID_PARAMETERS = 87
Global Const ERROR_NO_MORE_ITEMS = 259
Global Const KEY_ALL_ACCESS = &H3F
Global Const REG_OPTION_NON_VOLATILE = 0
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition 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 RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
Private Declare Function RegDeleteKey& Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String)
Private Declare Function RegDeleteValue& Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String)
'删除键
Public Function DeleteKey(lPredefinedKey As Long, sKeyName As String)
Dim lRetVal As Long
Dim hKey As Long
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = RegDeleteKey(lPredefinedKey, sKeyName)
RegCloseKey (hKey)
End Function
'删除键值
Public Function DeleteValue(lPredefinedKey As Long, sKeyName As String, sValueName As String)
Dim lRetVal As Long
Dim hKey As Long
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = RegDeleteValue(hKey, sValueName)
RegCloseKey (hKey)
End Function
'赋值(下一层)
Public Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
Dim lValue As Long
Dim sValue As String
Select Case lType
Case REG_SZ
sValue = vValue
SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
Case REG_DWORD
lValue = vValue
SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
End Select
End Function
'获取值(下一层)
Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
Dim cch As Long
Dim lrc As Long
Dim lType As Long
Dim lValue As Long
Dim sValue As String
On Error GoTo QueryValueExError
lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
If lrc <> ERROR_NONE Then Error 5
Select Case lType
Case REG_SZ:
sValue = String(cch, 0)
lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
If lrc = ERROR_NONE Then
vValue = Left$(sValue, cch)
Else
vValue = Empty
End If
Case REG_DWORD:
lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
If lrc = ERROR_NONE Then vValue = lValue
Case Else
lrc = -1
End Select
QueryValueExExit:
QueryValueEx = lrc
Exit Function
QueryValueExError:
Resume QueryValueExExit
End Function
'建立新键
Public Function CreateNewKey(lPredefinedKey As Long, sNewKeyName As String)
Dim hNewKey As Long
Dim lRetVal As Long
lRetVal = RegCreateKeyEx(lPredefinedKey, sNewKeyName, 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hNewKey, lRetVal)
RegCloseKey (hNewKey)
End Function
'Sub main()
' '函数在注册表的"HKEY_CURRENT_USER\Software"中建立了
' '一个SubKey1项并在其中建立了值,并在显示后删除建立
' '的值,如果你想通过RegEdit看到结果,可以将最后两句
' '删除,不过要记得手动删除建立的键值
' CreateNewKey HKEY_CURRENT_USER, "Software\SubKey1\SubKey2"
' SetKeyValue HKEY_CURRENT_USER, "Software\SubKey1\SubKey2", "Test", "This is just a test", REG_SZ
' MsgBox QueryValue(HKEY_CURRENT_USER, "Software\SubKey1\SubKey2", "Test")
' DeleteValue HKEY_CURRENT_USER, "Software\SubKey1\SubKey2", "Test"
' DeleteKey HKEY_CURRENT_USER, "Software\SubKey1\SubKey2"
'End Sub
'给指定的键值赋值
Public Function SetKeyValue(lPredefinedKey As Long, sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)
Dim lRetVal As Long
Dim hKey As Long
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
RegCloseKey (hKey)
End Function
'获取指定的键值
Public Function QueryValue(lPredefinedKey As Long, sKeyName As String, sValueName As String) As String
Dim lRetVal As Long
Dim hKey As Long
Dim vValue As Variant
lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = QueryValueEx(hKey, sValueName, vValue)
QueryValue = vValue
RegCloseKey (hKey)
End Function
Top
相关问题
- 注册表中这些键是什么意思????????????????
- ======为什么删不掉?注册表键。=======
- 3谁知道这几个注册表的键值是做什么的呢?
- 在注册表自动运行键Run里面添加kernel32.dll是什么病毒
- 请问注册表中的“REG_MULTI_SZ”类型的键值是什么来的?
- 在注册表中修改REG_DWORD类型键值,修改后不可用。这是为什么?
- 在注册表中修改REG_MULTI_SZ类型键值,修改后出现乱码。这是为什么?
- 在注册表中设置 “隐藏该监视器无法识别的模式” 的键是什么?
- 有谁知道点击http链接右键弹出菜单各项是在注册表中的什么位置?
- 困扰啊,请问注册表HKEY_CLASSES_ROOT\PROTOCOLS\Filter\text/xml这个键下是什么COM?




