Añadir al registro

  • 0 Respuestas
  • 1944 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Conectado ANTRAX

  • *
  • Administrator
  • Mensajes: 5706
  • Actividad:
    30%
  • Country: ar
  • Reputación 37
  • ANTRAX
  • Skype: underc0de.org
  • Twitter: @Underc0de
    • Ver Perfil
    • Underc0de
    • Email

Añadir al registro

  • en: Mayo 22, 2011, 09:57:14 pm
Enumerating the values under a Registry Key:
   There are three major steps involved in Enumerating values from registry.
   1. Open the Registry key
    2. Loop and print using RegEnumKey till the return value is not equal to ERROR_SUCCESS.
    3. Close the Registry key

Código: C
  1. #include <windows.h>
  2. #include <stdio.h>
  3. void main()
  4. {
  5.     char lszValue[100];
  6.     LONG lRet, lEnumRet;
  7.     HKEY hKey;
  8.     DWORD dwLength=100;
  9.     int i=0;
  10.     lRet = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE\\ADOBE", 0L, KEY_READ , &hKey);
  11.     if(lRet == ERROR_SUCCESS)
  12.     {
  13.          lEnumRet = RegEnumKey (hKey, i,lszValue,dwLength);
  14.          while(lEnumRet == ERROR_SUCCESS)
  15.          {
  16.               i++;
  17.               printf ("%s\n",lszValue);
  18.               lEnumRet = RegEnumKey (hKey, i,lszValue,dwLength);
  19.            }
  20.        }
  21.  
  22.      RegCloseKey(hKey);
  23. }
  24.  
  25.  
  26. Accessing a REG_DWORD value from Registry:
  27.    Accessing a DWORD from registry is simple. Open the Registry key and read it using RegQueryValueEx.
  28.  
  29. #include <windows.h>
  30. #include <stdio.h>
  31. void main()
  32. {
  33.     DWORD dwVersion;
  34.     HKEY hKey;
  35.     LONG returnStatus;
  36. DWORD dwType=REG_DWORD;
  37.    DWORD dwSize=sizeof(DWORD);
  38.     returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Path", 0L, KEY_ALL_ACCESS, &hKey);
  39.  
  40.     if (returnStatus  = = ERROR_SUCCESS)
  41.     {
  42.         returnStatus = RegQueryValueEx(hKey, "Value", NULL, &dwType,(LPBYTE)&dwVersion, &dwSize);
  43.         if (returnStatus == ERROR_SUCCESS)
  44.         {
  45.              printf("REG_DWORD value is %d\n", dwVersion);
  46.         }
  47.      }
  48.  
  49.     RegCloseKey(hKey);
  50. }
  51.  
  52. Note: The only error that might crop up during the usage of this function is due to assigning a wrong value for the dwSize. If the dwSize is smaller than the queried value, then the RegQueryEx will fail. This happens especially during repeated mixed usage of the same variables for reading DWORD as well as character arrays. This is very much untraceable and might also get missed during testing. So it is better to check this problem during coding itself.
  53. Accessing a REG_SZ from Registry:
  54.  
  55.  
  56. #include <windows.h>
  57. #include <stdio.h>
  58. void main()
  59. {
  60.      char lszValue[255];
  61.      HKEY hKey;
  62.      LONG returnStatus;
  63.      DWORD dwType=REG_SZ;
  64.      DWORD dwSize=255;
  65.      returnStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\INETMGR\\PARAMETERS", 0L,  KEY_ALL_ACCESS, &hKey);
  66.      if (returnStatus == ERROR_SUCCESS)
  67.      {
  68.           returnStatus = RegQueryValueEx(hKey, "HelpLocation", NULL, &dwType,(LPBYTE)&lszValue, &dwSize);
  69.           if (returnStatus == ERROR_SUCCESS)
  70.           {
  71.                printf("Value Read is %s\n", lszValue);
  72.           }
  73.        }
  74.      RegCloseKey(hKey);
  75. }
« Última modificación: Febrero 08, 2014, 05:49:17 pm por Expermicid »