最简单的方法是删除HKEY_CURRENT_USER\software\microsoft\internet explorer\typedurls\子键及其下的所有子键及键值(使用api RegDeleteKey),然后重建该子键(使用api RegCreateKey),我用delphi,VB不太清楚,供参考。
解决方案 »
- 字节数组。一般用什么作为分隔标志好。
- 一个Access中的OLE对象如何插入到SQLServer2000中Image对象中
- 为什么在win2000中会提示“部件‘mswebdvd.dll’或其附件之一不能正确注册:一个文件丢失或无效”,请问高手这是什么原因呢?在XP下是正常的!
- 迟到的问好
- 在线等待,来者有分,如何用一个VB程序得到当前桌面打开的窗口,并打开最下面一个窗口、谢谢
- 如何的判断 ADO 是否处于活动状态?
- 急问!Instr()函数的含义及用法!
- 请各位大侠,高人指教!!!
- 关于读写文件的问题,30
- 请问VB中如何得到当前窗口的句柄,象VC中用GetSafeHwnd()一样,可以吗?
- 如何获得其它窗口的信息?
- 如何实现两个窗体间的数据查询
要代码的话发信到 [email protected]
'作者: flyinnet
'Email: wh@ hongzhi.com
'
' 该模块用于替换vb里面的 SaveSetting getsetting ,getallsettings,deletesetting
' 等注册表函数,不同之处在于可以自己设置存放的位置,
'
' Visual Basic 6.0 sp3 调试通过,window 98(中文版) NT4.0(中文版), Window2000(中文版)均使用通过,
'
'注意:
'
' 1.getallsettings 返回的数组与原VB返回的数组不同,原getallsettings返回的数组为(n,1)
' 现在返回的为(1,n),原因是重定义数组只能是定义数组的最后一维,但使用没有什么影响,没必要再费力转换
'
' 2.getallsettings 返回的最大数据默认为255byte,如果需要更大,请设置MaxCount!
'
' 3,无法存取二进制格式,原vb函数似乎也不行
'
' 4,原deletesetting,和 savesetting 没有返回值 ,现在将返回boolean值,表示是否成功
'
'\\===================================================================================
' 使用时出现问题,或您有更好的想法,请发信给我
'\\===================================================================================Option Explicit
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type ACL
AclRevision As Byte
Sbz1 As Byte
AclSize As Integer
AceCount As Integer
Sbz2 As Integer
End Type
Private Type SECURITY_DESCRIPTOR
Revision As Byte
Sbz1 As Byte
Control As Long
Owner As Long
Group As Long
Sacl As ACL
Dacl As ACL
End Type
Public Enum PKey
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_LOCAL_MACHINE = &H80000002
HKEY_DYN_DATA = &H80000006
HKEY_CURRENT_USER = &H80000001
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CLASSES_ROOT = &H80000000
End Enum
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private 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, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegGetKeySecurity Lib "advapi32.dll" (ByVal hKey As Long, ByVal SecurityInformation As Long, pSecurityDescriptor As SECURITY_DESCRIPTOR, lpcbSecurityDescriptor As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private 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
Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" (ByVal hKey As Long, ByVal lpClass As String, lpcbClass As Long, ByVal lpReserved As Long, lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, lpftLastWriteTime As FILETIME) As Long
Private Declare Function RegLoadKey Lib "advapi32.dll" Alias "RegLoadKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpFile As String) As Long
Private 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
Private 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegReplaceKey Lib "advapi32.dll" Alias "RegReplaceKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpNewFile As String, ByVal lpOldFile As String) As Long
Private Declare Function RegRestoreKey Lib "advapi32.dll" Alias "RegRestoreKeyA" (ByVal hKey As Long, ByVal lpFile As String, ByVal dwFlags As Long) As Long
Private Declare Function RegSaveKey Lib "advapi32.dll" Alias "RegSaveKeyA" (ByVal hKey As Long, ByVal lpFile As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
Private Declare Function RegSetKeySecurity Lib "advapi32.dll" (ByVal hKey As Long, ByVal SecurityInformation As Long, pSecurityDescriptor As SECURITY_DESCRIPTOR) As Long
Private 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
Private 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegUnLoadKey Lib "advapi32.dll" Alias "RegUnLoadKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As LongPrivate Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_BINARY = 3 ' Free form binary
Private Const REG_CREATED_NEW_KEY = &H1 ' New Registry Key created
Private Const REG_DWORD = 4 ' 32-bit number
Private Const REG_DWORD_BIG_ENDIAN = 5 ' 32-bit number
Private Const REG_DWORD_LITTLE_ENDIAN = 4 ' 32-bit number (same as REG_DWORD)
Private Const REG_EXPAND_SZ = 2 ' Unicode nul terminated stringPrivate Const REG_LINK = 6 ' Symbolic Link (unicode)
Private Const REG_MULTI_SZ = 7 ' Multiple Unicode strings
Private Const REG_NONE = 0 ' No value type
Private Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
Private Const REG_NOTIFY_CHANGE_LAST_SET = &H4 ' Time stamp
Private Const REG_NOTIFY_CHANGE_NAME = &H1 ' Create or delete (child)
Private Const REG_NOTIFY_CHANGE_SECURITY = &H8
Private Const REG_OPENED_EXISTING_KEY = &H2 ' Existing Key opened
Private Const REG_OPTION_BACKUP_RESTORE = 4 ' open for backup or restore
Private Const REG_OPTION_CREATE_LINK = 2 ' Created key is a symbolic link
Private Const REG_OPTION_NON_VOLATILE = 0 ' Key is preserved when system is rebooted
Private Const REG_OPTION_RESERVED = 0 ' Parameter is reserved
Private Const REG_OPTION_VOLATILE = 1 ' Key is not preserved when system is rebooted
Private Const REG_REFRESH_HIVE = &H2 ' Unwind changes to last flush
Private Const REG_RESOURCE_LIST = 8 ' Resource list in the resource map
Private Const REG_RESOURCE_REQUIREMENTS_LIST = 10
Private Const REG_WHOLE_HIVE_VOLATILE = &H1 ' Restore whole hive volatile
Private Const REG_LEGAL_CHANGE_FILTER = (REG_NOTIFY_CHANGE_NAME Or REG_NOTIFY_CHANGE_ATTRIBUTES Or REG_NOTIFY_CHANGE_LAST_SET Or REG_NOTIFY_CHANGE_SECURITY)
Private Const REG_LEGAL_OPTION = (REG_OPTION_RESERVED Or REG_OPTION_NON_VOLATILE Or REG_OPTION_VOLATILE Or REG_OPTION_CREATE_LINK Or REG_OPTION_BACKUP_RESTORE)Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_NOTIFY = &H10
Private Const KEY_EVENT = &H1 ' Event contains key event record
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_SET_VALUE = &H2
'private 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))
'private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
'private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
'private Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
Private Const ERROR_SUCCESS = 0&
Private Const ERROR_BADDB = 1009&
Private Const ERROR_BADKEY = 1010&
Private Const ERROR_CANTOPEN = 1011&
Private Const ERROR_CANTREAD = 1012&
Private Const ERROR_CANTWRITE = 1013&
Private Const ERROR_REGISTRY_RECOVERED = 1014&
Private Const ERROR_REGISTRY_CORRUPT = 1015&
Private Const ERROR_REGISTRY_IO_FAILED = 1016&
Private Const ERROR_MORE_DATA = 234 ' dderror
Private Const ERROR_NO_MORE_ITEMS = 259&Private mSubKey As String
Private mKey As PKey
Private mMaxCount As LongProperty Let Subkey(theSubkey As String)
mSubKey = theSubkey
End Property
Property Get Subkey() As String
Subkey = mSubKey
End PropertyProperty Let key(thekey As PKey)
mKey = thekey
End PropertyProperty Get key() As PKey
key = mKey
End PropertyProperty Let MaxCount(theMaxCount As Long)
mMaxCount = theMaxCount
End PropertyProperty Get MaxCount() As Long
MaxCount = mMaxCount
End Property'//保存注册表项目
Function SaveSetting(AppName As String, section As String, key As String, setting As Variant) As Boolean
Dim ret As Long
Dim hKey As Long
Dim lSize As Long
Dim lType As Long
Dim sSetting As String
sSetting = CStr(setting)
On Error GoTo DError
ret = RegCreateKey(mKey, mSubKey & "\" & AppName & "\" & section, hKey)
If ret = ERROR_SUCCESS Then
lSize = lstrlenA(sSetting)
lType = REG_SZ
ret = RegSetValueEx(hKey, key, 0&, lType, ByVal sSetting, lSize)
If ret = ERROR_SUCCESS Then
SaveSetting = True
Else
SaveSetting = False
End If
Call RegCloseKey(hKey)
Else
SaveSetting = False
End If
Exit Function
DError:
SaveSetting = False
End Function'//读取注册表项目
Function GetSetting(AppName As String, section As String, key As String, Optional default As Variant) As Variant
Dim ret As Long
Dim hKey As Long
Dim lSize As Long
Dim stemp As String
On Error GoTo DError
If IsMissing(default) Then default = ""
ret = RegOpenKeyEx(mKey, mSubKey & "\" & AppName & "\" & section, 0&, KEY_QUERY_VALUE, hKey)
If ret = ERROR_SUCCESS Then
ret = RegQueryValueEx(hKey, key, 0&, REG_SZ, ByVal 0&, lSize)
If ret = ERROR_SUCCESS Then
stemp = String(lSize, Chr$(0))
ret = RegQueryValueEx(hKey, key, 0&, REG_SZ, ByVal stemp, lSize)
If ret = ERROR_SUCCESS Then
'此一段主要是为了适用于中文
stemp = Left$(stemp, lSize - 1)
Do While Right$(stemp, 1) = Chr$(0)
stemp = Left$(stemp, Len(stemp) - 1)
Loop
GetSetting = stemp
Else
GetSetting = default
End If
Else
GetSetting = default
End If
Call RegCloseKey(hKey)
Else
GetSetting = default
End If
Exit Function
DError:
GetSetting = ""
End Function'//枚举注册表项目
Function GetAllSettings(AppName As String, section As String) As Variant
Dim ret As Long
Dim hKey As Long
Dim lSize As Long
Dim lSizeName As Long
Dim stemp As String
Dim sTempName As String
Dim arrayTemp() As String
Dim VarTemp As Variant
Dim lIndex As Long
On Error GoTo DError
ret = RegOpenKeyEx(mKey, mSubKey & "\" & AppName & "\" & section, 0&, KEY_QUERY_VALUE, hKey)
If ret = ERROR_SUCCESS Then
lIndex = 0
Do
lSizeName = 255
sTempName = String(255, Chr$(0))
lSize = mMaxCount
stemp = String(mMaxCount, Chr$(0))
ret = RegEnumValue(hKey, lIndex, sTempName, lSizeName, 0&, REG_SZ, ByVal stemp, lSize)
If ret = ERROR_SUCCESS Then
ReDim Preserve arrayTemp(1, lIndex)
Do While Right$(sTempName, 1) = Chr$(0)
sTempName = Left$(sTempName, Len(sTempName) - 1)
Loop
Do While Right$(stemp, 1) = Chr$(0)
stemp = Left$(stemp, Len(stemp) - 1)
Loop
arrayTemp(0, lIndex) = sTempName
arrayTemp(1, lIndex) = stemp
lIndex = lIndex + 1
VarTemp = arrayTemp
Else
Exit Do
End If
Loop
Call RegCloseKey(hKey)
GetAllSettings = VarTemp
Exit Function
End If
DError:
End Function'//删除注册表项目
Function DeleteSetting(AppName As String, section As String, Optional key As String) As Boolean
Dim ret As Long
Dim hKey As Long
On Error GoTo DError
If key = "" Then
ret = RegDeleteKey(mKey, mSubKey & "\" & AppName & "\" & section)
If ret = ERROR_SUCCESS Then
DeleteSetting = True
Else
DeleteSetting = False
End If
Else
ret = RegOpenKeyEx(mKey, mSubKey & "\" & AppName & "\" & section, 0&, KEY_SET_VALUE, hKey)
If ret = ERROR_SUCCESS Then
ret = RegDeleteValue(hKey, key)
If ret = ERROR_SUCCESS Then
DeleteSetting = True
Else
DeleteSetting = False
End If
Call RegCloseKey(hKey)
Else
DeleteSetting = False
End If
End If
Exit Function
DError:
DeleteSetting = False
End FunctionPrivate Sub Class_Initialize()
mMaxCount = 255
mKey = HKEY_CURRENT_USER
mSubKey = "software"
End Sub
弄注册表不看这个很可惜 http://my.6to23.com/vbnetcn/vb6/vbjqq/vbjqq.htm