Lm th? no ? li?t k cc gi tr? c?a m?t kha Registry

D?ch tiu ? D?ch tiu ?
ID c?a bi: 178755 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Cc RegEnumValue ch?c nng cho php b?n ? li?t k cc gi tr? c?a m?t kha registry. Ci ?t chng tr?nh th?ng ?c lu gi? trong s? ng k?. Li?t k thng qua m?t kha s? ng k? cho php b?n ?c cc thi?t ?t ng k? c?a m?t chng tr?nh ? b?n c th? khi ph?c l?i cc thi?t ?t sau khi b?n ch?y chng tr?nh.

Bi vi?t ny cho b?n th?y lm th? no ? s? d?ng cc RegEnumValue ch?c nng ? li?t k cc gi tr? c?a m?t kha registry.

THNG TIN THM

Sau y l Visual Basic tuyn b? quy?n RegEnumValue:
   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

				
LU ?: Khai bo ch?c nng ?c li?t k trong API xem vn b?n cho ccRegEnumValue ch?c nng l khng chnh xc. Cc tham s? th? nm, lpReserved, nn ?c thng qua b?i gi tr? nh minh h?a ? trn. ? bi?t thm chi ti?t, xin vui l?ng xem bi vi?t sau trong c s? ki?n th?c Microsoft:
173009 PRB: Th?i gian ch?y l?i 87 s? d?ng ch?c nng RegEnumValue
Ph?n ti?p theo minh ho? lm th? no ? t?o m?t d? n m?u hi?n th? cc gi tr? c?a m?t kha s? ng k? ?c ch? ?nh trong m?t h?p danh sch.

V d?-by-step

  1. B?t ?u m?t d? n tiu chu?n EXE m?i trong Visual Basic. Form1 ?c t?o ra theo m?c ?nh.
  2. Thm m?t CommandButton v m?t i?u khi?n ListBox ? Form1. B?i v? nhi?u ng?i trong s? cc m?c l di, b?n nn m? r?ng ListBox qua ton b? chi?u r?ng c?a h?nh th?c. Chi?u cao c?a ListBox nn l m?t s? d?ng.
  3. Dn o?n m? sau vo c?a s? m? c?a Form1:
          Option Explicit
    
          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 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 RegCloseKey Lib "advapi32.dll" _
              (ByVal hKey As Long) As Long
    
          Const HKEY_CLASSES_ROOT = &H80000000
          Const HKEY_CURRENT_USER = &H80000001
          Const HKEY_LOCAL_MACHINE = &H80000002
          Const HKEY_USERS = &H80000003
    
          Const ERROR_SUCCESS = 0&
    
          Const SYNCHRONIZE = &H100000
          Const STANDARD_RIGHTS_READ = &H20000
          Const STANDARD_RIGHTS_WRITE = &H20000
          Const STANDARD_RIGHTS_EXECUTE = &H20000
          Const STANDARD_RIGHTS_REQUIRED = &HF0000
          Const STANDARD_RIGHTS_ALL = &H1F0000
          Const KEY_QUERY_VALUE = &H1
          Const KEY_SET_VALUE = &H2
          Const KEY_CREATE_SUB_KEY = &H4
          Const KEY_ENUMERATE_SUB_KEYS = &H8
          Const KEY_NOTIFY = &H10
          Const KEY_CREATE_LINK = &H20
          Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
                            KEY_QUERY_VALUE Or _
                            KEY_ENUMERATE_SUB_KEYS Or _
                            KEY_NOTIFY) And _
                            (Not SYNCHRONIZE))
    
          Const REG_DWORD = 4
          Const REG_BINARY = 3
          Const REG_SZ = 1
    
          Private Sub Command1_Click()
             Dim lngKeyHandle As Long
             Dim lngResult As Long
             Dim lngCurIdx As Long
             Dim strValue As String
             Dim lngValueLen As Long
             Dim lngData As Long
             Dim lngDataLen As Long
             Dim strResult As String
    
             lngResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
                     "SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls", _
                      0&, _
                      KEY_READ, _
                      lngKeyHandle)
    
             If lngResult <> ERROR_SUCCESS Then
                 MsgBox "Cannot open key"
                 Exit Sub
             End If
    
             lngCurIdx = 0
             Do
                lngValueLen = 2000
                strValue = String(lngValueLen, 0)
                lngDataLen = 2000
    
                lngResult = RegEnumValue(lngKeyHandle, _
                                         lngCurIdx, _
                                         ByVal strValue, _
                                         lngValueLen, _
                                         0&, _
                                         REG_DWORD, _
                                         ByVal lngData, _
                                         lngDataLen)
                lngCurIdx = lngCurIdx + 1
    
             If lngResult = ERROR_SUCCESS Then
                strResult = lngCurIdx & ": " & Left(strValue, lngValueLen)
                List1.AddItem strResult
             End If
    
             Loop While lngResult = ERROR_SUCCESS
             Call RegCloseKey(lngKeyHandle)
          End Sub
    					
  4. Trn cc B?t ?u tr?nh n, nh?p vo Ch?y, ho?c b?m phm F5, ch?y chng tr?nh. Nh?p vo CommandButton. T?t c? cc gi tr? cho kha registry sau y xu?t hi?n trong h?p danh sch:
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\SharedDlls

THAM KH?O

? bi?t thm chi ti?t v? vi?c s? d?ng Visual Basic ? thao tc thi?t ?t ng k?, b?m vo nh?ng con s? bi vi?t d?i y ? xem cc bi vi?t trong c s? ki?n th?c Microsoft:
145679 Lm th? no ? s? d?ng Registry API ? lu v l?y cc thi?t ?t
267908 Lm th? no ? li?t k cc Subkeys m?t kha s? ng k? m?

Thu?c tnh

ID c?a bi: 178755 - L?n xem xt sau cng: 19 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
T? kha:
kbapi kbhowto kbmt KB178755 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:178755

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com