简体   繁体   English

Windows上通过C ++的唯一CPU ID

[英]Unique CPU ID on Windows via C++

Well I would like to get an unique CPU ID so I can get an UNIQUE identification for each machine. 好吧,我想获得一个唯一的CPU ID,以便为每台计算机获得一个唯一标识。 I did check __cpuid() from windows.h library, but the problem is that the ID it gets, it's the ID of all types of CPU, if you have an I3 Core processor and I have an I3 core processor, it will give the same "Unique ID". 我确实从windows.h库中检查了__cpuid(),但是问题是它获取的ID是所有类型CPU的ID,如果您有I3 Core处理器,而我有I3 Core处理器,它将给出相同的“唯一ID”。

Here is what I came up with to make a CPU ID from the __cpuid() that returns the same information on processors of the same type: 这是我从__cpuid()获取CPU ID的方法,该ID在相同类型的处理器上返回相同的信息:

std::string GetCPUID(){

            int CPUInfo[4] = {-1};
            __cpuid(CPUInfo, 0);
             if (CPUInfo[0] < 4)
            return ""; //Error on retrieving

            stringstream st;
            for(int i = 0; i <= 3; i++){ 
                         st << CPUInfo[i];
                    }

            return st.str();

}

I also checked a program called "Hardware ID Extractor" that works fine, it actually returns a UNIQUE CPU ID as the GUI as I wanted, so they made available a DLL so we can extract the CPU ID it generated , I tried everything with the cleanest code with the DLL and following their example but it seems that it returns nothing when ran on Windows 7. a lot of other people were complaining about this on Windows 7 via the DLL, even though the GUI on windows 7 returns the correct CPU ID. 我还检查了一个名为“ Hardware ID Extractor”的程序,该程序运行良好,它实际上返回了我想要的GUI唯一身份CPU ID,因此它们提供了一个DLL,以便我们提取生成的CPU ID,我尝试了使用使用DLL并遵循其示例的最干净的代码,但似乎在Windows 7上运行时它什么也没有返回。即使Windows 7上的GUI返回了正确的CPU ID,很多其他人还是在Windows 7上通过DLL抱怨这一点。 。

Showing my work in the Hardware ID Extractor, 在硬件ID提取器中显示我的工作,

Here is the site where I downloaded the DLL (Where I chose the link of C++, VB, .NET): http://www.soft.tahionic.com/download-hdd_id/free-download/free%20download.html 这是我下载DLL的网站(我选择了C ++,VB,.NET的链接): http : //www.soft.tahionic.com/download-hdd_id/free-download/free%20download.html

And here is the DLL itself to download: http://www.soft.tahionic.com/download-hdd_id/free-download/DLL%20compressed/HardwareIDExtractorC.dll 这是要下载的DLL本身: http : //www.soft.tahionic.com/download-hdd_id/free-download/DLL%20compressed/HardwareIDExtractorC.dll

This is the code I got from Hardware ID Extractor (I'm using Visual Studio 2008): 这是我从硬件ID提取器(我正在使用Visual Studio 2008)获得的代码:

#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;

int main (){

    char* (__stdcall *GetIDESerialNumber)(BYTE);

    HINSTANCE DllInst = NULL;
    if (DllInst == NULL) DllInst = LoadLibrary("C:\\HardwareIDExtractorC.dll");
    printf( "LoadLibrary error %d\n", GetLastError() );
    if (DllInst) {
        GetIDESerialNumber = (char* (__stdcall*)(BYTE))GetProcAddress(DllInst, "GetIDESerialNumber");

    //Now call the imported function
        cout << "SN: " <<  GetIDESerialNumber(0);   // 0 = first IDE hard drive in your system 
    }else{
        printf(" - Not Loaded");
    }

    _getch();



return 0;
}

In the visual studio output it shows that the DLL was executed by saying: 在visual studio输出中,它通过以下方式显示了DLL的执行:

'Test.exe': Loaded 'C:\HardwareIDExtractorC.dll', Binary was not built with debug information.

And the program output that I get is: LoadLibrary error 998 - Not loaded 我得到的程序输出是: LoadLibrary error 998 - Not loaded

Someone know what I can do to get a CPU ID Unique, like in the application Hardware ID Extractor? 有人知道如何才能获得唯一的CPU ID,例如在应用程序中使用Hardware ID Extractor吗? I need to get a CPU ID because if I get HDD information, the user may format their Hard Drive and the program will stop working, as I'm designing it to work only that specified computer. 我需要获取CPU ID,因为如果获得HDD信息,用户可能会格式化其硬盘驱动器,并且该程序将停止运行,因为我将其设计为仅在指定的计算机上运行。

I'm using Windows 7 32 bits Ultimate and Intel I3 Core Processor (if that helps in anyway). 我正在使用Windows 7 32位旗舰版和英特尔I3核心处理器(如果有帮助的话)。

I hope I was clear in my question. 我希望我的问题很清楚。 Thanks in advance! 提前致谢!

You cannot make this work. 您无法完成这项工作。 Intel introduced a Processor Serial Number back in the Pentium III design, readable with cpuid. 英特尔引入了奔腾III设计中的处理器序列号,可通过cpuid读取。 That raised a huge stink because of privacy concerns and Intel was forced to back down. 由于隐私问题 ,这引起了巨大的反响,英特尔被迫退缩。 The feature got removed in later Pentium III designs and has never been put back. 该功能已在以后的Pentium III设计中删除,并且从未取消。

You are going to have to use another source for a fingerprint. 您将不得不使用另一个指纹来源。 Don't use just one, collect a bunch and only declare it invalid when more than one changed. 不要只使用一个,而是收集一堆,并且仅当更改了多个时才宣布它无效。 Use the NIC MAC address, RAM size, disk volume serial number, stuff like that. 使用NIC MAC地址,RAM大小,磁盘卷序列号之类的东西。 There are already thousands of questions about that at SO. 在SO上已经有成千上万的问题。

Hardware ID Extractor is reliable and easy to use. 硬件ID提取器可靠且易于使用。 I have it. 我有 Because I purchased the DLL and the source code long time ago I didn't had to purchased the upgrades. 因为我很久以前购买了DLL 源代码,所以不必购买升级程序。 I just changed the code by myself. 我只是自己更改了代码。

Hans thanks for the answer, you know this program called "Hardware ID Extractor" it claims it retrieves a CPU ID 汉斯(Hans)感谢您的回答,您知道此程序称为“硬件ID提取器”,它声称它会检索CPU ID

Yes. 是。 The DLL provides not only the CPU ID and the HDD IDE ID but many other hardware related statistics (IDs). DLL不仅提供CPU ID和HDD IDE ID,而且还提供许多其他与硬件相关的统计信息(ID)。 I have tried it on multiple CPUs (both AMD and Intel) and it works like a charm. 我已经在多个CPU(AMD和Intel)上进行了尝试,它的工作原理很吸引人。

The scheme 方案

The cheapest 'protection' is the serial number. 最便宜的“保护”是序列号。 That just sucks big time. 那真是糟透了。 A single mindless customer makes it available on Internet and everybody has your program FOR FREE! 一个没有头脑的客户就可以在Internet上使用它,每个人都可以免费获得您的程序! Not mentioning that 'hackers' today don't bother to break your software protection. 更不用说今天的“黑客”不用费心破坏您的软件保护。 They will buy your software with a fake credit card and will publish the key on web OR they will buy the software with a valid credit card and then they will use the 30 days money back policy to get the money back. 他们将使用伪造的信用卡购买您的软件,并在网络上发布密钥,或者他们将使用有效的信用卡购买软件,然后他们将使用30天退款政策来取回资金。 Some mad software resellers such as Plimus (yes, stay away from Plimus) are enforcing this on the software vendors. 一些疯狂的软件经销商,例如Plimus(是的,请远离Plimus)正在对软件供应商强制执行此操作。 Classic serial numbers are as dead as dinosaurs. 经典的序列号像恐龙一样死了。

The other recommendation, the server-based protection, is also not good at all. 另一个建议,即基于服务器的保护也不是很好。 A bit harder to cheat by fake credit card 'hackers' and also won't leak keys all over the Internet. 假信用卡“黑客”更难作弊,而且不会在整个互联网上泄露密钥。 But you will lose at least half of your customers because these days everybody has a firewall/antivirus that will block your program from connecting to the server. 但是您将失去至少一半的客户,因为这些天每个人都有防火墙/防病毒软件,它们会阻止您的程序连接到服务器。 And what about those that are mobile? 那那些移动的呢? Or that have only random/rare access to internet? 还是只有随机/稀少的互联网访问权限? I don't even dare to speak about those that are working behind of the firewall of an institution/company/organization. 我什至不敢谈论那些在机构/公司/组织的防火墙后面工作的人。 Most of those companies are 'ruled' by mindless network administrators that cut ANY program except Internet Explorer (not even Firefox) from accessing the Internet. 这些公司中的大多数都是由无意识的网络管理员“统治”的,他们将除Internet Explorer(甚至不是Firefox)之外的任何程序都禁止访问Internet。 I have been there. 我去过那里。 I have done that. 我已经做到了。 Believe me, IT IS NIGHTMARE! 相信我,这就是噩梦! In other to have a program connected to internet you have to go to administration fill lots of request forms and finally MAYBE, MAYBE, they will let the program access the Internet. 要使程序连接到Internet,您必须去管理部门填写大量申请表,最后MAYBE,MAYBE,他们将允许该程序访问Internet。 Through a proxy maybe. 通过代理。

Anyway, it is quite easy to do a reliable key-based based protection for your program: send a key to the customer BUT don't send a classic key but a hardware-based key. 无论如何,对程序进行可靠的基于密钥的保护是很容易的:将密钥发送给客户,但不发送传统密钥而是发送基于硬件的密钥。 This way the key will work only in that SPECIFIC system. 这样,密钥将仅在该特定系统中起作用。 You can even post an announcement on your web site: "Please feel free to make this key public. I don't give a damn" :) 您甚至可以在您的网站上发布公告:“请随时公开此密钥。我不该死” :)

Just don't rely on a single hardware ID (CPU only for example) but on all of them. 只是不依赖单个硬件ID(例如,仅CPU),而是全部依赖。 Allow the user to change/upgrade all its hardware components except one. 允许用户更改/升级其所有硬件组件(一个除外)。 So, as long as they won't change the entire computer the license will work. 因此,只要他们不会更改整个计算机,许可证就可以使用。 Since a new computer is purchased every 3.4 years (I have found the statistics on Internet) you should allow the user to ask for 3 new keys (license reactivation). 由于每3.4年购买一台新计算机(我在Internet上找到了统计数据),因此您应该允许用户要求输入3个新密钥(重新激活许可证)。 Probably you will release a new version before the 3.4 years interval expires. 您可能会在3.4年的时间间隔到期之前发布新版本。 So, the customers will have to buy the upgrade and get a new key anyway. 因此,客户无论如何都必须购买升级并获得新的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM