need get motherboard serial or cpu serial

i see this code in old topic :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma warning(disable:4996) // disable microsoft rubbish (::fopen may be unsafe etc.)
#include <iostream>
#include <string>
#include <stdio.h>
#include <cctype>
#include <iomanip>

std::string get_system_uuid()
{
    if( std::system( "wmic csproduct get uuid > test.txt" ) == 0 )
    {
        auto file = ::fopen( "test.txt", "rt, ccs=UNICODE" ) ; // open the file for unicode input

        enum { BUFFSZ = 1000, UUID_SZ = 36 };
        wchar_t wbuffer[BUFFSZ] ; // buffer to hold unicode characters

        if( file && // file was succesffully opened
            ::fgetws( wbuffer, BUFFSZ, file ) && // successfully read (and discarded) the first line
            ::fgetws( wbuffer, BUFFSZ, file ) ) // successfully read the second line
        {
            char cstr[BUFFSZ] ; // buffer to hold the converted c-style string
            if( ::wcstombs( cstr, wbuffer, BUFFSZ ) > UUID_SZ ) // convert unicode to utf-8
            {
                std::string uuid = cstr ;
                while( !uuid.empty() && std::isspace( uuid.back() ) ) uuid.pop_back() ; // discard trailing white space
                return uuid ;
            }
        }
    }

    return {} ; // failed, return empty string
}

int main()
{
    const std::string smbios_uuid = get_system_uuid() ;
    std::cout << "system uuid (smbios): " << std::quoted(smbios_uuid) << '\n' ;

    // if( smbios_uuid == "..." ) { /* run certain function */ }
}


i need make ban hardware system in my game i need code to get motherboard serial or cpu serial like upper code
sorry for my bad English
Last edited on
#push
UP
up
Implementing a hardware banning system will take a bit more sophistication than that code you posted. You can very easily circumvent the system() call by placing a user-created wmic.exe in the same directory as the calling program that outputs a modified test.txt.

Do not ban by hardware. You will be relying on information provided by the user's own system. This can easily be spoofed by the user and renders the ban ineffective and opens up potential to abuse.

An example of abuse would be someone spoofing the hardware configuration of many systems (serial numbers are well... serial in nature... A7-372B5 comes after A7-372B4, etc) and getting the hardware banned potentially locking out legitimate users/customers with no real means to verify the legitimacy.


If you really still want to ban by hardware, use the tried and true methods to do so, either write a kernel mode driver to give you unrestricted access to the hardware to get less unreliable information, or use the less reliable NIC MAC address or HDD serial.

I must stress that this is a very bad approach to a problem that was solved a long time ago. Use a network-based authentication system.
Topic archived. No new replies allowed.