關於部落格
職場生活筆記....熱情依然在
  • 50699

    累積人氣

  • 1

    今日人氣

    1

    追蹤人氣

如何讀寫Windows 的Registry

#include <windows.h>
#include <stdio.h>

void main()
{
        HKEY hKey, hSubkey, hSubsubkey;
        if (RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &hKey) == ERROR_SUCCESS)
        {
            if (RegOpenKey(hKey, "IBM", &hSubkey) == ERROR_SUCCESS) 
                {
                if (RegOpenKey(hSubkey, "Trace Facility", &hSubsubkey) == ERROR_SUCCESS) 
                {
                    char *szData;
                    DWORD dwType, dwLen;
                    szData = new char[101];
                    dwLen = 100;
                    if (RegQueryValueEx(hSubsubkey, "LOCATION", NULL, &dwType, (unsigned char *)szData, &dwLen) == ERROR_SUCCESS) 
                     {
                        printf("Data: %sn", szData);
                        RegCloseKey(hSubsubkey);
                        RegCloseKey(hSubkey);
                        RegCloseKey(hKey);
                     }
                     else 
                     {
                        printf("RegQueryValueEx failn");
                  }
                    delete []szData;
              }
             else 
             {
                    printf("RegOpenKey subsub fail!n");
             }
            }
            else 
            {
                printf("RegOpenKey sub fail!n");
             }
        }
        else 
        {
            printf("RegOpenKey fail!n");
        }
}



相簿設定
標籤設定
相簿狀態