去这里下载吧:
http://asp.6to23.com/vcprogram/source/source_main.asp

解决方案 »

  1.   

    #define _WIN32_WINNT 0x4000   #include <stdio.h>
       #include <tchar.h>
       #include <windows.h>   void _tmain (void)
       {
       HKEY hKey = NULL;
       HKEY hCfgKey = NULL;   __try
       {
          HW_PROFILE_INFO HwProfile;
       
          ULONG ulCurrentConfig = 1;
          ULONG ulSize = 0;   
          UUID NewGuid;
          TCHAR RegStr[MAX_PATH];      TCHAR pszRegIDConfigDB[] =    TEXT("System\\CurrentControlSet\\Control\\IDConfigDB");
          TCHAR pszRegKnownDockingStates[] = TEXT("Hardware Profiles");
          TCHAR pszRegCurrentConfig[] = TEXT("CurrentConfig");
          TCHAR pszRegHwProfileGuid[] = TEXT("HwProfileGuid");
          UCHAR * pszUuidString;      // Initialize to all 0s.
          ZeroMemory(&HwProfile, sizeof(HwProfile));      // Open IDConfigDB key.
          if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, pszRegIDConfigDB, 0,
                           KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
          {
             __leave;
          }      // Get current profile sub-key value.
          ulSize = sizeof(ULONG);      
          if (RegQueryValueEx(hKey, pszRegCurrentConfig, NULL, NULL,
                              (LPBYTE)&ulCurrentConfig, &ulSize) !=    ERROR_SUCCESS)
          {
             __leave;      
          }      // Open current profile sub-key.
          wsprintf(RegStr, TEXT("%s\\%04u"), pszRegKnownDockingStates,    ulCurrentConfig);      
          if (RegOpenKeyEx(hKey, RegStr, 0, 
                           KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WRITE,    &hCfgKey) != ERROR_SUCCESS)
          {
             __leave;      
          }      // See if HwProfileGuid value exists?
          ulSize = HW_PROFILE_GUIDLEN * sizeof(TCHAR);      
          if (RegQueryValueEx(hCfgKey, pszRegHwProfileGuid, NULL, NULL,
                              (LPBYTE)&HwProfile.szHwProfileGuid, &ulSize) !=    ERROR_SUCCESS ||
                              HwProfile.szHwProfileGuid[0] == TEXT('\0')) 
          {         
             RPC_STATUS status;         // Create a UID for the HwProfileGuid value.
             if (((status = UuidCreate(&NewGuid)) != RPC_S_OK) && 
                 (status != RPC_S_UUID_LOCAL_ONLY)) 
             {
                __leave;      
             }         // Convert the UID to registry entry form.
             if (UuidToString(&NewGuid, &pszUuidString) == RPC_S_OK)
             {
                lstrcpy((LPBYTE)&HwProfile.szHwProfileGuid, TEXT("{"));
                lstrcat((LPBYTE)&HwProfile.szHwProfileGuid, pszUuidString);      
                lstrcat((LPBYTE)&HwProfile.szHwProfileGuid, TEXT("}"));
                _strupr((LPBYTE)&HwProfile.szHwProfileGuid);      
                RpcStringFree(&pszUuidString);   
             }         // Create or set the HwProfileGuid value.
             ulSize = (lstrlen(HwProfile.szHwProfileGuid) + 1) * sizeof(TCHAR);         
             if (RegSetValueEx(hCfgKey, pszRegHwProfileGuid, 0, REG_SZ,
                               (LPBYTE)HwProfile.szHwProfileGuid, ulSize) !=    ERROR_SUCCESS) 
             {
                __leave;      
             }
          }      // Get current hardware profile.
          if (GetCurrentHwProfile(&HwProfile))
          {
             _tprintf(TEXT("DockInfo = %d\n"), HwProfile.dwDockInfo);
             _tprintf(TEXT("Profile Guid = %s\n"), HwProfile.szHwProfileGuid);
             _tprintf(TEXT("Friendly Name = %s\n"), HwProfile.szHwProfileName);
          }
          else
          {
             _tprintf(TEXT("Error [0x%x]: GetCurrentHwProfile() failed.\n"),    GetLastError());
          }
       }   __finally
       {
          // Close any open key.
          if (hCfgKey)
             RegCloseKey(hCfgKey);      if (hKey)
             RegCloseKey(hKey);
       }   return;
       }