2010-11-08 Regedit 讀取寫入 應用範例 (VB) 38010 0 VB Regedit 讀取寫入 應用範例 (VB) Option Explicit Const REG_SZ = 1 Const REG_EXPAND_SZ = 2 Const REG_BINARY = 3 Const REG_DWORD = 4 Const HKEY_CLASSES_ROOT = &H80000000 Const HKEY_CURRENT_USER = &H80000001 Const HKEY_LOCAL_MACHINE = &H80000002 Const HKEY_USERS = &H80000003 Const HKEY_PERFORMANCE_DATA = &H80000004 Const ERROR_BADKEY = 2 Const ERROR_ACCESS_DENIED = 8 Const ERROR_SUCCESS = 0 Dim xpass '註冊碼 Dim Y '使用者 主機版機碼 '結果 ' '位置:SYSTEM\ControlSet001\Control\Windows '下有 8 個子鍵: '------------------------------ '鍵名:CSDVersion 型態:REG_DWORD 內容:768 '鍵名:CSDReleaseType 型態:REG_DWORD 內容:0 '鍵名:Directory 型態:REG_EXPAND_SZ 內容:C:\WINDOWS '鍵名:ErrorMode 型態:REG_DWORD 內容:0 '鍵名:NoInteractiveServices 型態:REG_DWORD 內容:0 '鍵名:SystemDirectory 型態:REG_EXPAND_SZ 內容:C:\WINDOWS\system32 '鍵名:ShellErrorMode 型態:REG_DWORD 內容:1 '鍵名:ShutdownTime 型態:REG_BINARY 內容:C4 82 71 D0 38 6E C9 01 Private Function Get_MB_SNo() As String Dim strCls As String, strKey As String Dim WMI As Object Set WMI = GetObject("winmgmts:") strCls = "Win32_BaseBoard" ' WMI 類別 strKey = strCls & ".Tag=""Base Board""" Get_MB_SNo = Trim(WMI.InstancesOf(strCls)(strKey).SerialNumber) End Function Private Sub Command1_Click() Dim REGIFSN '讀取REGEDIT的 HKEY_CURRENT_USER\Software\VB and VBA Program Settings\專案一\Settings MainHeight的值 REGIFSN = GetSetting("專案一", "SETTINGS", "MainHeight") If Val(REGIFSN) <> xpass Then MsgBox Y Else MsgBox "恭喜通過註冊" End If ' Print "主機板序號 : " & Get_MB_SNo End Sub Private Sub Command2_Click() '存入REGEDIT的 HKEY_CURRENT_USER\Software\VB and VBA Program Settings\專案一\Settings MainHeight的值 SaveSetting "專案一", "SETTINGS", "MainHeight", xpass End Sub Private Sub Command3_Click() Msgbox y '秀出原始數字 '秀出正確密碼 MsgBox xpass End Sub Private Sub Form_Load() Dim i Y = 0 For i = 1 To Len(Trim(Get_MB_SNo)) Y = Y + Asc(Mid(Get_MB_SNo, i)) Next i Y = Y * 125 xpass =Y+99 '在form_load就算好密碼 Debug.Print xpass End Sub 如有錯誤 歡迎指正 回首頁