English
HOME | PROJECTS | C++ CLASSES | c\c++ source code | Gallery | Guestbook | BW Servers | Contact me | Login

<< Reading Windows registry >>

visits: 1761


Ecco un esempio di programma che accede ai registri di Windows.
Questo programma prende dai registri la cartella di installazione di FireFox 2.
ps: so che il codice è scritto in modo orribile, ma l'ho scritto quando ero agli inizi.

  1. //*************************************//
  2. //******** created by mamo139 *********//
  3. //*** http://mamo139.altervista.org ***//
  4. //*************************************//
  5.  
  6.  
  7. /******************************/
  8. /***** Mozilla Patch **********/
  9. /******************************/
  10.  
  11. HKEY hKey;
  12. DWORD disposition, size, type;
  13. char *stringData;
  14.  
  15. //Apertura registro
  16. RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Mozilla\\Mozilla Firefox", 0, NULL,
  17. REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disposition);
  18.  
  19. //lunghezza stringa
  20. long result = RegQueryValueEx(hKey, "CurrentVersion", 0, &type, NULL, &size);
  21.  
  22. //controllo errore lunghezza
  23. // if (result != ERROR_SUCCESS) MessageBox(NULL, "The value named 'CurrentVersion1' was not found in the registry",
  24. // "Problem", MB_OK);
  25. // else if (type == REG_SZ) {
  26.  
  27. //Lettura stringa
  28. stringData = new char[size];
  29. RegQueryValueEx(hKey, "CurrentVersion",0, &type, (BYTE*)stringData, &size);
  30.  
  31. //MessageBox(NULL, stringData,"What the registry says", MB_OK);
  32.  
  33.  
  34. //}
  35. // else MessageBox(NULL, "The value named 'Message' does not contain string data", "Problem", MB_OK);
  36.  
  37.  
  38. RegCloseKey(hKey);
  39.  
  40.  
  41. char mozilla_url[1000] = "Software\\Mozilla\\Mozilla Firefox\\";
  42. strcat(mozilla_url,stringData);
  43. strcat(mozilla_url,"\\Main");
  44. //MessageBox(NULL, mozilla_url,"What the registry says", MB_OK);
  45.  
  46. HKEY hKey2;
  47. DWORD disposition2, size2, type2;
  48.  
  49. RegCreateKeyEx(HKEY_CURRENT_USER, mozilla_url, 0, NULL,
  50. REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey2, &disposition2);
  51.  
  52. long result2 = RegQueryValueEx(hKey2, "PathToExe", 0, &type2, NULL, &size2);
  53.  
  54. char *mozexe_url;
  55. mozexe_url = new char[size2];
  56. RegQueryValueEx(hKey2, "PathToExe",0, &type2, (BYTE*)mozexe_url, &size2);
  57. MessageBox(NULL, mozexe_url,"What the registry says", MB_OK);
  58.  
  59. RegCloseKey(hKey2);
  60.  
  61. //mozilla patch è mozexe_url
  62. /******************************/
Website version: 1.03.01 by mamo139. - All the source codes are intended to be released under "GNU GPL version 3".