匿名使用者
匿名使用者 發問時間: 電腦與網際網路程式設計 · 1 0 年前

VB 6.0 讀取 regedit 某個值[很急]

VB 6.0 讀取 regedit 某個值

然後顯示到 text1.text ?

例如

[HKEY_CURRENT_USER\Software\Yahoo\pager\Test]

"plural"=dword:00000001

讀取 名稱為 plural 類型為 REG_dword 的值

顯示在 text1.text 也就是 顯示00000001

1 個解答

評分
  • 是我
    Lv 5
    1 0 年前
    最佳解答

    請新增一 GetRegDWord 函式:

    Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long

    Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

    Public 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

    Public Const ERROR_SUCCESS = 0&

    Public Const REG_DWORD = 4

    Function GetRegDWord(ByVal HKey As Long, ByVal strPath As String, ByVal strValueName As String) As Long

    Dim lResult As Long

    Dim lType As Long

    Dim lData As Long

    Dim lSize As Long

    Dim lHandle As Long

    RegOpenKey HKey, strPath, lHandle

    lSize = Len(lData)

    lResult = RegQueryValueEx(lHandle, strValueName, 0&, lType, lData, lSize)

    If lResult = ERROR_SUCCESS Then

    If lType = REG_DWORD Then

    GetRegDWord = lData

    'Else 該 Registry Name 的值並非 DWORD 型態之錯誤處理

    End If

    End If

    RegCloseKey lHandle

    End Function

    用法:

    Dim lDWordValue As Long

    lDWordValue = GetRegDWord(HKEY_CURRENT_USER, "Software\Yahoo\pager\Test", "plural")

    text1.text = Right(String(7, "0") & Hex(lDWordValue), 8)

還有問題?馬上發問,尋求解答。