Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: patrocle on April 27, 2019, 01:57:29 pm

Title: Read the wmic or GUID
Post by: patrocle 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
	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
Title: Re: Read the wmic or GUID
Post by: hidefromkgb 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 (https://www.google.com/search?q=prevent+multiple+application+instances+site:stackoverflow.com) 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.
Title: Re: Read the wmic or GUID
Post by: patrocle 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.
Title: Re: Read the wmic or GUID
Post by: hidefromkgb 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
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...

}
Title: Re: Read the wmic or GUID
Post by: patrocle on April 27, 2019, 05:18:42 pm
thanks again, compiled!

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

Title: Re: Read the wmic or GUID
Post by: hidefromkgb on April 28, 2019, 02:34:45 pm
Code
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 ) );
}
Title: Re: Read the wmic or GUID
Post by: patrocle on April 28, 2019, 06:06:25 pm

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


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

Title: Re: Read the wmic or GUID
Post by: stahta01 on April 28, 2019, 06:10:21 pm
Please read this FAQ and this website rules.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)
http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)

Tim S.
Title: Re: Read the wmic or GUID
Post by: hidefromkgb 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…
Title: Re: Read the wmic or GUID
Post by: patrocle on April 29, 2019, 06:43:14 pm
but the
Code
stringMachineGUID
is not declarated and i dont think is a string, look to be a char.
Title: Re: Read the wmic or GUID
Post by: hidefromkgb 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.
Title: Re: Read the wmic or GUID
Post by: patrocle 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.
Title: Re: Read the wmic or GUID
Post by: hidefromkgb on May 03, 2019, 02:58:49 pm
Damn it. That was the first google result (https://stackoverflow.com/a/6623809).

Code
std::wstring wtmp(MachineGUID);
std::string stringMachineGUID(wtmp.begin(), wtmp.end());
Title: Re: Read the wmic or GUID
Post by: patrocle on May 06, 2019, 04:20:00 pm
now a real problem, guid is empty  :o
Title: Re: Read the wmic or GUID
Post by: stahta01 on May 06, 2019, 11:32:32 pm
Please read this FAQ and this website rules.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)
http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)

Tim S.
Title: Re: Read the wmic or GUID
Post by: patrocle on May 06, 2019, 11:41:51 pm
my apologies, I thought it is 'General' and I have any chances to solve this 'issue'
Sorry again