How to get HWID

5.9k Views Asked by At

I am trying to get HWID through the hwProfileInfo class, but it returns me that i can't convert WCHAR [39] to String.

string getHWID(){
  string hardware_guid

  HW_PROFILE_INFO hwProfileInfo;
  GetCurrentHwProfile(&hwProfileInfo);
  hardware_guid = hwProfileInfo.szHwProfileGuid;

  return hardware_guid;
}

Than i tried this way, but it returns me just "{"

hardware_guid = (char*)hwProfileInfo.szHwProfileGuid;

I know there are some more ways in Google, but i didn't find any working variants. May be there are some people, who can say the 100% method?

2

There are 2 best solutions below

4
Csgo MlgCom On BEST ANSWER

This is the answer to my question.

string getHWID(){  
  HW_PROFILE_INFO hwProfileInfo;
  GetCurrentHwProfile(&hwProfileInfo);
  wstring hwidWString = hwProfileInfo.szHwProfileGuid;  
  string hwid(hwidWString.begin(), hwidWString.end());

  return hwid;
}
0
Norbert Willhelm On

There are two methods: 1st You can use std::wstring, which uses wchar_t, instead of std::string, which uses char. 2nd You can use GetCurrentHwProfileA instead of GetCurrentHwProfileW, which will be defined as GetCurrentHwProfile if UNICODE is defined.