News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Read the wmic or GUID

Started by patrocle, April 27, 2019, 01:57:29 PM

Previous topic - Next topic

patrocle

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

hidefromkgb

#1
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.

patrocle

Thank you for the reply!
QuoteIf 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.

hidefromkgb

#3
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...

}

patrocle

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


hidefromkgb

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 ) );
}

patrocle


stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

hidefromkgb

Quote from: patrocle on April 28, 2019, 06:06:25 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...

patrocle

but the stringMachineGUID is not declarated and i dont think is a string, look to be a char.

hidefromkgb

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.

patrocle

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.

hidefromkgb

Damn it. That was the first google result.

std::wstring wtmp(MachineGUID);
std::string stringMachineGUID(wtmp.begin(), wtmp.end());

patrocle

now a real problem, guid is empty  :o

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]