0

我已经能够检索我的系统序列号,但是如何将序列号本身传递给变量?

    int main()
    {
        char newSerial;
        int (*ptr) (const char[]);

        ptr = system;

        ptr("wmic bios get serialnumber");      
    }

运行我的代码后,屏幕显示:

    SerialNumber
    xxxxxxxxxxxxx

就像这样。但我想要的只是将“x”传递给一个 char 变量,因为它有一个破折号。调用序列号的程序究竟是从哪里来的?有什么建议么?(Windows 7 x64)

4

3 回答 3

1

官方认可的通过 C++ 以编程方式访问 WMI 的方法是 WMI 的COM API。具体参见 WMI C++ Application Examples下的示例。

另一方面,如果您想快速访问序列号,请在您的程序中添加以下内容:

system("wmic bios get serialnumber > sn.txt");
wchar_t sn[16];
FILE* fp = fopen("sn.txt","r, ccs=UTF-8");
fgetws(sn,16,fp); //dummy read of first line
fgetws(sn,16,fp); //now sn contains 2nd line

fclose(fp);          //cleanup temp file
remove("sn.txt");  

printf("The serial Number is: %ws\n",sn);
于 2012-02-06T22:29:59.917 回答
0

这是不使用文本文件的更好方法

QProcess proc;
//proc.start("cscript " + path, QIODevice::ReadWrite);
proc.start("wmic bios get serialnumber",QIODevice::ReadWrite);
//qDebug() << path;
proc.waitForFinished();
QString uID = proc.readAll();
qDebug()<<uID; // serial number of the laptop
于 2015-01-30T02:40:08.633 回答
0
    ShellExecute(NULL, L"open", L"cmd.exe", L"/c wmic bios get serialnumber > sn.txt", NULL, SW_HIDE);

wchar_t sn[16];
FILE* fp = fopen("sn.txt","r, ccs=UTF-8");
fgetws(sn,16,fp); //dummy read of first line
fgetws(sn,16,fp); //now sn contains 2nd line

fclose(fp);          //cleanup temp file
remove("sn.txt");  

printf("The serial Number is: %ws\n",sn);
于 2017-07-25T10:00:32.527 回答