70 likes | 303 Views
Registry. 參考資料 : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/structure_of_the_registry.asp. Values. Key. Structure of the Registry. Registry stores data in tree format. A key can have any # of values Registry Value Type. No “ / ”.
E N D
Registry 參考資料: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/structure_of_the_registry.asp
Values Key Structure of the Registry • Registry stores data in tree format • A key can have any # • of values • Registry Value Type No “/” Regedit command
Little-endian: Bytes at lower addresses have lower significance. 0x12345678 78 56 34 12 低位址 高位址 Registry Value Type
Opening, Creating, and Closing Keys • If you want to add data to the registry, you must create or open a key LONG RegOpenKeyEx( HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult );
Open a key LONG RegOpenKeyEx( HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult ); must be zero Access Mask KeyHandle 範例程式 KEY_QUERY_VALUE KEY_ENUMERATE_SUB_KEYS KEY_NOTIFY … HKEY hKey; LONG lRet; lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Office", 0, KEY_QUERY_VALUE, &hKey ); if( lRet == ERROR_SUCCESS ) MessageBox(NULL,"You have Office software","ok",MB_OK); else MessageBox(NULL,"fail","fail",MB_OK); RegCloseKey( hKey );
Create a Key LONG RegCreateKeyEx( HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved, LPTSTR lpClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition); 已經存在的 key 你要建立的 key 0 指定KEY 的object type 屬性 存取權限 回傳的 handle 描述該 key 是否存在
Create a key: a demo int APIENTRY WinMain( …){ HKEY hkey; LONG result; DWORD dwDisposition; result=RegCreateKeyEx(HKEY_LOCAL_MACHINE, // KEY _T("SOFTWARE\\井民全測試"), // 你要建立的KEY 0, // 0 NULL, // 指定KEY 的object type字串 REG_OPTION_NON_VOLATILE, // 指定永久的KEY KEY_ALL_ACCESS, // 指定所有的存取權限 NULL, // 預設 security &hkey, // 傳回 Key handle &dwDisposition); // 該 key是否已經存在 if(result==ERROR_SUCCESS){ if(dwDisposition==REG_CREATED_NEW_KEY) MessageBox(NULL,_T("新增成功"),_T("系統資訊"),MB_OK); else MessageBox(NULL,_T("目前這個key已經存在"),_T("系統資訊"),MB_OK); } else MessageBox(NULL,_T("Error"),_T("錯誤訊息"),MB_OK); RegCloseKey(hkey); }