Hello all coders,
I'm trying to add a way to read wmic or GUID and then use it as a string like that http://prntscr.com/nhk98b
The goal is to identify players using multiple accounts.
I found a sample but i can't compile it, i need some lib :(
FILE* CommandResult = _popen("wmic csproduct get uuid", "rt"); //send the command to the cmd and return a pointer to the command result
char line[256]; //a buffer to read from the file
while(fgets(line, 256, CommandResult)) printf(line); //read and print all lines one by one
_pclose(CommandResult);
Can someone help me with a working CB sample? Please
Okay, digging a little bit further into your code snippet I realized that your task is to uniquely identify a Windows PC.
You could`ve stated that earlier =)
Well, getting a unique Windows installation GUID can be done as follows:
HKEY hKey;
WCHAR *MachineGUID[128];
DWORD dwBufferSize = sizeof(MachineGUID);
ULONG nError;
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ, &hKey);
nError = RegQueryValueExW(hKey, L"MachineGuid", 0, NULL, (LPBYTE)MachineGUID, &dwBufferSize);
RegCloseKey(hkey);
if (nError == ERROR_SUCCESS) {
/// do something with MachineGUID...
}
thanks again, compiled!
now, how could i have a string with uuid?
somthing like that:
string GetUUID()
{
HKEY hKey;
WCHAR *MachineGUID[128];
DWORD dwBufferSize = sizeof(MachineGUID);
ULONG nError;
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ, &hKey);
nError = RegQueryValueExW(hKey, L"MachineGuid", 0, NULL, (LPBYTE)MachineGUID, &dwBufferSize);
RegCloseKey(hKey);
if (nError == ERROR_SUCCESS) {
//do something with MachineGUID...
//return hKey;
}
}
// here i will use the uuid
m_RemoteSocket->PutBytes( m_GPSProtocol->SEND_GPSC_INIT3( 2, GetUUID() ) ); // verify the uuid
ULONG GetUUID(WCHAR *MachineGUID, DWORD *dwBufferSize) {
HKEY hKey;
ULONG nError;
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ, &hKey);
nError = RegQueryValueExW(hKey, L"MachineGuid", 0, NULL, (LPBYTE)MachineGUID, dwBufferSize);
RegCloseKey(hKey);
return nError;
}
WCHAR MachineGUID[512];
DWORD dwBufferSize = sizeof(MachineGUID);
if (GetUUID(MachineGUID, &dwBufferSize) == ERROR_SUCCESS) {
// convert MachineGUID from WCHAR* to string
...
m_RemoteSocket->PutBytes( m_GPSProtocol->SEND_GPSC_INIT3( 2, stringMachineGUID ) );
}
Damn it. That was the first google result (https://stackoverflow.com/a/6623809).
std::wstring wtmp(MachineGUID);
std::string stringMachineGUID(wtmp.begin(), wtmp.end());