Author Topic: Read the wmic or GUID  (Read 1342 times)

Offline patrocle

  • Multiple posting newcomer
  • *
  • Posts: 17
Read the wmic or GUID
« on: April 27, 2019, 01:57:29 pm »
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 :(

Code: [Select]
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

Offline hidefromkgb

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: Read the wmic or GUID
« Reply #1 on: April 27, 2019, 02:39:38 pm »
Although this is not related to C::B, I`ll try directing you to an answer.
If I get your problem right, you need to ensure only one instance of your app is running on the target machine. This is how it`s done.

Bear in mind though that this is not in any way a panacea, for sophicticated players may use additional PCs, virtual machines, diassemblers, and lots of other cool things to overcome the restriction you are trying to impose.
« Last Edit: April 27, 2019, 02:45:28 pm by hidefromkgb »

Offline patrocle

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Read the wmic or GUID
« Reply #2 on: April 27, 2019, 03:06:31 pm »
Thank you for the reply!
Quote
If I get your problem right, you need to ensure only one instance of your app is running on the target machine. This is how it`s done.
No, its only about a UUID , nothing to do with multiple instances. About "virtual machines, diassemblers, and lots of other cool things" is fine, i don't have hackers players.

A sample will really help.

Offline hidefromkgb

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: Read the wmic or GUID
« Reply #3 on: April 27, 2019, 04:14:16 pm »
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:

Code: [Select]
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...

}
« Last Edit: April 27, 2019, 04:18:14 pm by hidefromkgb »

Offline patrocle

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Read the wmic or GUID
« Reply #4 on: April 27, 2019, 05:18:42 pm »
thanks again, compiled!

now, how could i have a string with uuid?
somthing like that:
Code: [Select]
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


Offline hidefromkgb

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: Read the wmic or GUID
« Reply #5 on: April 28, 2019, 02:34:45 pm »
Code: [Select]
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 ) );
}

Offline patrocle

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Read the wmic or GUID
« Reply #6 on: April 28, 2019, 06:06:25 pm »

added your code: http://prntscr.com/nhxvs9 


and i got this error: http://prntscr.com/nhxvgi


Offline stahta01

  • Lives here!
  • ****
  • Posts: 6581
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline hidefromkgb

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: Read the wmic or GUID
« Reply #8 on: April 28, 2019, 06:23:18 pm »
and i got this error: http://prntscr.com/nhxvgi
Of course, that`s because I don`t know which data type that SEND_GPSC_INIT3() function accepts, so I considered it to be up to you to convert…

Offline patrocle

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Read the wmic or GUID
« Reply #9 on: April 29, 2019, 06:43:14 pm »
but the
Code: [Select]
stringMachineGUID is not declarated and i dont think is a string, look to be a char.

Offline hidefromkgb

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: Read the wmic or GUID
« Reply #10 on: April 29, 2019, 10:11:05 pm »
It`s undeclared for one simple reason: I do not know what data type SEND_GPSC_INIT3() accepts.
It is up to you to declare stringMachineGUID and give it a value converted from MachineGUID`s *WCHAR.

Offline patrocle

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Read the wmic or GUID
« Reply #11 on: May 03, 2019, 11:50:01 am »
accept string, that't i ask for string output.  *WCHAR is not accepted and the guid result is empty :( I give up

Thanks for your help mate.

Offline hidefromkgb

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: Read the wmic or GUID
« Reply #12 on: May 03, 2019, 02:58:49 pm »
Damn it. That was the first google result.

Code: [Select]
std::wstring wtmp(MachineGUID);
std::string stringMachineGUID(wtmp.begin(), wtmp.end());

Offline patrocle

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Read the wmic or GUID
« Reply #13 on: May 06, 2019, 04:20:00 pm »
now a real problem, guid is empty  :o

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6581
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org