Click here to Skip to main content
15,896,730 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionerrors while executing vc++ code Pin
angelshroff9-Jun-06 1:56
angelshroff9-Jun-06 1:56 
AnswerRe: errors while executing vc++ code Pin
Laxman Auti9-Jun-06 2:06
Laxman Auti9-Jun-06 2:06 
AnswerRe: errors while executing vc++ code Pin
Sarath C9-Jun-06 2:14
Sarath C9-Jun-06 2:14 
AnswerRe: errors while executing vc++ code Pin
Hamid_RT9-Jun-06 2:20
Hamid_RT9-Jun-06 2:20 
QuestionC++ HDD Serial Number Pin
anwar10269-Jun-06 1:42
anwar10269-Jun-06 1:42 
AnswerRe: C++ HDD Serial Number Pin
Sarath C9-Jun-06 1:50
Sarath C9-Jun-06 1:50 
AnswerRe: C++ HDD Serial Number [modified] Pin
Laxman Auti9-Jun-06 1:57
Laxman Auti9-Jun-06 1:57 
AnswerRe: C++ HDD Serial Number Pin
Viorel.9-Jun-06 2:30
Viorel.9-Jun-06 2:30 
If you need volume's serial number (for logical disks C:, D:, etc.), you can use GetVolumeInformation function.

If you need serial numbers of your hard disks as physical devices, you can follow the famous Windows Management Instrumentation (WMI) way, which does not look so simple:

#define _WIN32_WINNT 0x0400
#include <objbase.h>
#include <comdef.h>
#include <Wbemidl.h>

# pragma comment(lib, "wbemuuid.lib")

_COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator));
_COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices));
_COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, __uuidof(IEnumWbemClassObject));
_COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));


int main()
{

    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    CoInitializeSecurity(
        NULL,
        -1,
        NULL,
        NULL,
        RPC_C_AUTHN_LEVEL_DEFAULT,
        RPC_C_IMP_LEVEL_IMPERSONATE,
        NULL,
        EOAC_NONE,
        NULL);

    IWbemLocatorPtr locator;

    CoCreateInstance(
        CLSID_WbemLocator,             
        0, 
        CLSCTX_INPROC_SERVER, 
        IID_IWbemLocator, 
        (LPVOID *)&locator
        );

    IWbemServicesPtr services;

    locator->ConnectServer(
        _bstr_t(L"ROOT\\CIMV2"),
        NULL,
        NULL,
        0,
        NULL,
        0,
        0,
        &services
        );


    IEnumWbemClassObjectPtr enumerator;
    services->ExecQuery(
        bstr_t("WQL"), 
        bstr_t("SELECT * FROM Win32_DiskDrive"),
        WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
        NULL,
        &enumerator);

    IWbemClassObjectPtr object = 000;

    for( ; ; )
    {
        ULONG ret;
        enumerator->Next(WBEM_INFINITE, 1, &object, &ret);

        if( ret == 0) break;

        _variant_t variant;

        object->Get(L"Caption", 0, &variant, 0, 0);

        MessageBox(0, _bstr_t(variant), "The serial number is:", MB_OK);
    }

    return 0;
    //
    // TODO: check any call for errors
    //
}

Hope it helps.
GeneralRe: C++ HDD Serial Number Pin
anwar10269-Jun-06 2:52
anwar10269-Jun-06 2:52 
GeneralRe: C++ HDD Serial Number Pin
Viorel.9-Jun-06 3:15
Viorel.9-Jun-06 3:15 
GeneralRe: C++ HDD Serial Number Pin
anwar10269-Jun-06 4:06
anwar10269-Jun-06 4:06 
GeneralRe: C++ HDD Serial Number Pin
David Crow9-Jun-06 3:25
David Crow9-Jun-06 3:25 
Questionkalk Pin
J51219829-Jun-06 1:24
J51219829-Jun-06 1:24 
AnswerRe: kalk Pin
Sarath C9-Jun-06 1:34
Sarath C9-Jun-06 1:34 
AnswerRe: kalk Pin
toxcct9-Jun-06 1:36
toxcct9-Jun-06 1:36 
JokeRe: kalk Pin
Laxman Auti9-Jun-06 2:11
Laxman Auti9-Jun-06 2:11 
AnswerRe: kalk Pin
_AnsHUMAN_ 9-Jun-06 2:12
_AnsHUMAN_ 9-Jun-06 2:12 
GeneralRe: kalk Pin
J51219829-Jun-06 18:21
J51219829-Jun-06 18:21 
Questiontrouble with _beginthread Pin
NoName II9-Jun-06 1:01
NoName II9-Jun-06 1:01 
AnswerRe: trouble with _beginthread Pin
Laxman Auti9-Jun-06 1:08
Laxman Auti9-Jun-06 1:08 
GeneralRe: trouble with _beginthread Pin
NoName II9-Jun-06 1:20
NoName II9-Jun-06 1:20 
GeneralRe: trouble with _beginthread Pin
Cedric Moonen9-Jun-06 1:24
Cedric Moonen9-Jun-06 1:24 
AnswerRe: trouble with _beginthread Pin
Michael Dunn9-Jun-06 1:09
sitebuilderMichael Dunn9-Jun-06 1:09 
AnswerRe: trouble with _beginthread Pin
Hamid_RT9-Jun-06 1:19
Hamid_RT9-Jun-06 1:19 
GeneralRe: trouble with _beginthread Pin
Cedric Moonen9-Jun-06 1:22
Cedric Moonen9-Jun-06 1:22 

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.