| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 354 人关注过本帖
标题:读写注册表的问题,求指点,刚接触不懂
只看楼主 加入收藏
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:324
专家分:435
注 册:2012-1-29
结帖率:88.24%
收藏
已结贴  问题点数:20 回复次数:4 
读写注册表的问题,求指点,刚接触不懂

'=========================
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 RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 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
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
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1&
Private Const REG_EXPAND_SZ = 2&
Private Const REG_BINARY = 3&
Private Const REG_DWORD = 4&
Private Const ERROR_SUCCESS = 0&

'写入注册表字符串键值

Private Sub SetString(hKey As Long, strPath As String, strValue As String, strdata As String, lngType As Long)

Dim keyhand As Long
RegCreateKey hKey, strPath, keyhand
RegSetValueEx keyhand, strValue, 0, lngType, ByVal strdata, Len(strdata) + 8
RegCloseKey keyhand
End Sub
'获得注册表值
Private Function GetString(hKey As Long, strPath As String, strValue As String)

Dim keyhand As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
Dim lValueType As Long 'new add
RegOpenKey hKey, strPath, keyhand
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Or lValueType = REG_EXPAND_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left$(strBuf, intZeroPos - 1)
Else: GetString = strBuf
End If
End If
End If
End Function
'=======================================
Private Sub Command1_Click()
SetString HKEY_LOCAL_MACHINE, "software\管理", "注", "值", ZCfile  'ZCfile是一个变量里面是一个字符串,
                                                                    '长度有98个字节为什么写入的时候提示ByRef参数不符?要什么弄?关键是问题出在哪里?在学!
end  sub                                                             'ZCfile=3B98E2DFFC6CB06A89DCB0D5C60A02069D3D9048DB16A7EEE539E93E3618CBE7AA53CA0B650DFD85C4F59FA156F7A2CC                                                                           
搜索更多相关主题的帖子: 注册表 
2012-12-02 01:54
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:5 
Option Explicit

'=========================
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 RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 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
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
Private Const HKEY_LOCAL_MACHINE As Long = &H80000002
Private Const REG_SZ As Long = 1&
Private Const REG_EXPAND_SZ As Long = 2&
Private Const REG_BINARY As Long = 3&
Private Const REG_DWORD As Long = 4&
Private Const ERROR_SUCCESS As Long = 0&

'写入注册表字符串键值
Private Sub SetString(ByVal hKey As Long, strPath As String, strValue As String, strData As String, ByVal lngType As Long)
    Dim keyhand As Long
    Dim lRet As Long
    lRet = RegCreateKey(hKey, strPath, keyhand)
    If lRet = ERROR_SUCCESS Then
        RegSetValueEx keyhand, strValue, 0, lngType, ByVal strData, Len(strData) + 1
        RegCloseKey keyhand
    End If
End Sub
'获得注册表值
Private Function GetString(hKey As Long, strPath As String, strValue As String) As String
    Dim keyhand As Long
    Dim lResult As Long
    Dim strBuf As String
    Dim lDataBufSize As Long
    Dim intZeroPos As Integer
    Dim lValueType As Long 'new add
    RegOpenKey hKey, strPath, keyhand
    lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
    If lValueType = REG_SZ Or lValueType = REG_EXPAND_SZ Then
        strBuf = String$(lDataBufSize, vbNullChar)
        lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal strBuf, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            intZeroPos = InStr(strBuf, vbNullChar)
            If intZeroPos > 0 Then
                GetString = Left$(strBuf, intZeroPos - 1)
            Else: GetString = strBuf
            End If
        End If
    End If
End Function

'=======================================
Private Sub Command1_Click()
    SetString HKEY_LOCAL_MACHINE, "software\管理", "注", "值", REG_SZ   'ZCfile是一个变量里面是一个字符串,
                                                                    '长度有98个字节为什么写入的时候提示ByRef参数不符?要什么弄?关键是问题出在哪里?在学!
                                                                    'ZCfile=3B98E2DFFC6CB06A89DCB0D5C60A02069D3D9048DB16A7EEE539E93E3618CBE7AA53CA0B650DFD85C4F59FA156F7A2CC
    Debug.Print GetString(HKEY_LOCAL_MACHINE, "software\管理", "注")
End Sub
'ZCfile 是神马类型。
2012-12-02 16:21
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:324
专家分:435
注 册:2012-1-29
收藏
得分:0 
'ZCfile是一个变量存储的是md5加密后的加密码应该是字符型吧?

学习--------------学习-------------------学习--------------------!!
2012-12-02 16:36
Artless
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:4211
专家分:28888
注 册:2009-4-8
收藏
得分:5 
以下是引用wxflw在2012-12-2 16:36:29的发言:

'ZCfile是一个变量存储的是md5加密后的加密码应该是字符型吧?

ByRef参数不符

无知
2012-12-02 20:19
ych9631
Rank: 1
等 级:新手上路
帖 子:4
专家分:5
注 册:2012-12-2
收藏
得分:5 
回复 4楼 Artless
版主我有一个问题!一段程序出错了,不知为何,求指导!
2012-12-02 20:21
快速回复:读写注册表的问题,求指点,刚接触不懂
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012043 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved