讀取登錄檔內機碼

讀取登錄檔內機碼

如何用VB讀取登錄檔的機碼

'
兩種方式 

' 1.
使用 API 

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 RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" 
            (ByVal hKey As Long, _ 
            ByVal lpValueName As String) 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 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 

(
較麻煩

 

================================================================



' 2.
使用 Wsh ( Windows Scripting Host ) 

    Dim WshShell As Object 
    Set WshShell = CreateObject("WScript.Shell") '
建立 Wsh Shell 物件 
    MsgBox WshShell.RegRead("登錄檔機碼") ' 透過該物件 RegRead 方法 讀取登錄檔某機碼