Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Service not created correctly under windows 11 but any older version. Pin
Randor 24-Sep-23 7:08
professional Randor 24-Sep-23 7:08 
Questionfingerprint sensor code with c++ Pin
ibiere21-Sep-23 23:56
ibiere21-Sep-23 23:56 
AnswerRe: fingerprint sensor code with c++ Pin
CPallini22-Sep-23 0:52
mveCPallini22-Sep-23 0:52 
QuestionType of array and printf specifiers Pin
Member 114540620-Sep-23 4:40
Member 114540620-Sep-23 4:40 
AnswerRe: Type of array and printf specifiers Pin
Mircea Neacsu20-Sep-23 5:11
Mircea Neacsu20-Sep-23 5:11 
AnswerRe: Type of array and printf specifiers Pin
k505420-Sep-23 5:36
mvek505420-Sep-23 5:36 
AnswerRe: Type of array and printf specifiers Pin
CPallini20-Sep-23 5:51
mveCPallini20-Sep-23 5:51 
QuestionHow to get disk model and serial number for the disk Windows is installed on Pin
JohnCodding19-Sep-23 20:41
JohnCodding19-Sep-23 20:41 
I was trying to get the following to work:
C++
#include <iostream>
#include <string>
#include <array>

std::string exec(const char* cmd) {
    std::array<char, 128> buffer;
    std::string result;
    std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
    if (!pipe) {
        throw std::runtime_error("popen() failed!");
    }
    while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
        result += buffer.data();
    }
    return result;
}

void main() {
    std::cout << exec("wmic bootconfig get description");
    std::cout << exec("wmic diskdrive where DeviceID='\\.\PHYSICALDRIVE3' get model,serialnumber");
}

The first exec is running fine and giving the right return, but I'm having problems with the second exec, where I'm getting: ERROR: Description = Invalid query. In my search for a fix for that error, I found that because I'm using C++ I should be using native wmi queries, but unfortunately each result with code examples that I found were "like 3 pages" of code. Does anyone know of some more simple examples for wmi queries?

As for the code, I'm trying to get the model and serial number of the disk that the OS is installed on for some unique identification of app install and some other minor checks. And for this, I found that using wmic bootconfig get description, you can parse that result (Description\Device\Harddisk3\Partition1, 3 is the index) and get the index of the disk the OS is installed on, then using that index and wmic diskdrive where DeviceID='\\.\PHYSICALDRIVE3' get model,serialnumber where you change the 3 from PHYSICALDRIVE3 with the index from last command, you get the model and serial number. The code above is just a test to see the commands working, later I was going to parse the result and update the second exec call, right now it's using the index for my PC that I know were the OS is installed.

And yes, I know that the user can simply install the OS on a different disk and so the model and/or serial number would be different, but having to go though all that is enough of a hindrance to actually affect my use case, as I only care when the app is launched, and not on how many machines is installed on, that is IF the user finds that I'm using this verification method in the first place.

Any help is appreciated!
AnswerRe: How to get disk model and serial number for the disk Windows is installed on Pin
Richard MacCutchan19-Sep-23 21:59
mveRichard MacCutchan19-Sep-23 21:59 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
Valentinor19-Sep-23 22:15
Valentinor19-Sep-23 22:15 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
Richard MacCutchan19-Sep-23 22:26
mveRichard MacCutchan19-Sep-23 22:26 
AnswerRe: How to get disk model and serial number for the disk Windows is installed on Pin
Richard MacCutchan19-Sep-23 22:28
mveRichard MacCutchan19-Sep-23 22:28 
AnswerRe: How to get disk model and serial number for the disk Windows is installed on Pin
JohnCodding19-Sep-23 22:57
JohnCodding19-Sep-23 22:57 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
David Crow20-Sep-23 2:08
David Crow20-Sep-23 2:08 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
trønderen20-Sep-23 10:34
trønderen20-Sep-23 10:34 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
jschell20-Sep-23 13:13
jschell20-Sep-23 13:13 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
trønderen21-Sep-23 6:29
trønderen21-Sep-23 6:29 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
Richard MacCutchan20-Sep-23 22:03
mveRichard MacCutchan20-Sep-23 22:03 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
jschell21-Sep-23 4:57
jschell21-Sep-23 4:57 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
trønderen21-Sep-23 6:23
trønderen21-Sep-23 6:23 
AnswerRe: How to get disk model and serial number for the disk Windows is installed on Pin
Dave Kreskowiak20-Sep-23 13:23
mveDave Kreskowiak20-Sep-23 13:23 
AnswerRe: How to get disk model and serial number for the disk Windows is installed on Pin
Randor 20-Sep-23 22:34
professional Randor 20-Sep-23 22:34 
Questionwrite a progrrame create a calculator (using function) Pin
CHIRAG VAJA 202318-Sep-23 20:15
CHIRAG VAJA 202318-Sep-23 20:15 
AnswerRe: write a progrrame create a calculator (using function) Pin
Victor Nijegorodov18-Sep-23 20:26
Victor Nijegorodov18-Sep-23 20:26 
RantRe: write a progrrame create a calculator (using function) Pin
Richard Deeming18-Sep-23 21:23
mveRichard Deeming18-Sep-23 21:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.