1 / 7

Registry

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 “ / ”.

toan
Download Presentation

Registry

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Registry 參考資料: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/structure_of_the_registry.asp

  2. 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

  3. Little-endian: Bytes at lower addresses have lower significance. 0x12345678 78 56 34 12 低位址 高位址 Registry Value Type

  4. 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 );

  5. 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 );

  6. 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 是否存在

  7. 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); }

More Related