Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get the motherboard serial number on Win machine?
Forum Updated to NodeBB v4.3 + New Features

How to get the motherboard serial number on Win machine?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 3.3k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MucipM Offline
    MucipM Offline
    Mucip
    wrote on last edited by
    #1

    Hi,
    I want to get physical ModherBoard ID and Disc ID on Windows machine. I found this website from microsoft MSDN.

    But I couldn't get correct result. İt's getting error on first step.

    If I run this than I will use query like 'Win32_PhysicalMedia' and 'Win32_BaseBoard' to get my demands.

    I use Qt 5.14 and Qt-Creator 4.11.0 on Win 10.

    Regards,
    Mucip:)

    1 Reply Last reply
    0
    • MucipM Mucip

      @SGaist ,
      hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);

      It looks this return FALSE... :(

      Regards,
      Mucip:)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #6

      @Mucip said in How to get the motherboard serial number on Win machine?:

      CoInitializeEx

      Googling for CoInitializeEx qt, does https://stackoverflow.com/questions/2979113/qcoreapplication-qapplication-with-wmi ("QCoreApplication QApplication with WMI") address your issue?

      MucipM 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        You might want to share the error you are getting.

        In any case, did you try to run the code at the bottom of the article ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        MucipM 3 Replies Last reply
        1
        • SGaistS SGaist

          Hi,

          You might want to share the error you are getting.

          In any case, did you try to run the code at the bottom of the article ?

          MucipM Offline
          MucipM Offline
          Mucip
          wrote on last edited by
          #3

          Hi @SGaist ,
          The error is

          Failed to initialize COM library. Error code = 0x -7ffefefa

          Which code should I run? I coudn't see...

          Regards,
          Mucip:)

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            You might want to share the error you are getting.

            In any case, did you try to run the code at the bottom of the article ?

            MucipM Offline
            MucipM Offline
            Mucip
            wrote on last edited by
            #4

            @SGaist
            I already copy all the code in to Qt-Creator if you mean C++ codes in the bottom of the page?

            Regards,
            Mucip:)

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              You might want to share the error you are getting.

              In any case, did you try to run the code at the bottom of the article ?

              MucipM Offline
              MucipM Offline
              Mucip
              wrote on last edited by
              #5

              @SGaist ,
              hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);

              It looks this return FALSE... :(

              Regards,
              Mucip:)

              JonBJ Chris KawaC 2 Replies Last reply
              0
              • MucipM Mucip

                @SGaist ,
                hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);

                It looks this return FALSE... :(

                Regards,
                Mucip:)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @Mucip said in How to get the motherboard serial number on Win machine?:

                CoInitializeEx

                Googling for CoInitializeEx qt, does https://stackoverflow.com/questions/2979113/qcoreapplication-qapplication-with-wmi ("QCoreApplication QApplication with WMI") address your issue?

                MucipM 1 Reply Last reply
                0
                • JonBJ JonB

                  @Mucip said in How to get the motherboard serial number on Win machine?:

                  CoInitializeEx

                  Googling for CoInitializeEx qt, does https://stackoverflow.com/questions/2979113/qcoreapplication-qapplication-with-wmi ("QCoreApplication QApplication with WMI") address your issue?

                  MucipM Offline
                  MucipM Offline
                  Mucip
                  wrote on last edited by
                  #7

                  Hi @JonB ,
                  As the website adwised I changed the "COINIT_MULTITHREADED" parameter to "COINIT_APARTMENTTHREADED" in first step.
                  But in this case I get error in second step like below:

                  Failed to initialize security. Error code = 0x -7ffefee7

                  Regards,
                  Mucip:)

                  1 Reply Last reply
                  0
                  • MucipM Mucip

                    @SGaist ,
                    hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);

                    It looks this return FALSE... :(

                    Regards,
                    Mucip:)

                    Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @Mucip said:

                    It looks this return FALSE... :(

                    FALSE returned from CoInitializeEx does not mean it failed. It means COM is already initialized on that thread. QApplication does that. Changing the parameter causes you to have two initialization attempts with different apartments and that causes that second error.

                    You should use the FAILED macro to check for the result of CoInitializeEx. It checks if the returned value is <0, so FALSE , which is defined as 0, does not mean it failed.

                    JonBJ 1 Reply Last reply
                    3
                    • Chris KawaC Chris Kawa

                      @Mucip said:

                      It looks this return FALSE... :(

                      FALSE returned from CoInitializeEx does not mean it failed. It means COM is already initialized on that thread. QApplication does that. Changing the parameter causes you to have two initialization attempts with different apartments and that causes that second error.

                      You should use the FAILED macro to check for the result of CoInitializeEx. It checks if the returned value is <0, so FALSE , which is defined as 0, does not mean it failed.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #9

                      @Chris-Kawa
                      ...which is also what the code on the stackoverflow link showed to the OP...

                      Chris KawaC 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @Chris-Kawa
                        ...which is also what the code on the stackoverflow link showed to the OP...

                        Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @JonB And yet he continued as if it didn't so I thought I'd make it clear ;)

                        1 Reply Last reply
                        1
                        • MucipM Offline
                          MucipM Offline
                          Mucip
                          wrote on last edited by
                          #11

                          Hi All,
                          I checked this website.

                          He add the below lines in the begining of the code.

                          bool WMICommunication::connect()
                          {
                              // result code from COM calls
                                  HRESULT hr = 0;
                                  BSTR resource = SysAllocString(L"ROOT\\CIMV2");
                                  CoUninitialize();
                          
                          
                                  hr = CoInitializeEx(0, COINIT_MULTITHREADED);
                          
                          
                          

                          Now everything worked well. No error but no result either. :)

                          The result message is:
                          Connected to ROOT\CIMV2 WMI namespace

                          OS Name : 0x167ad7b1f38

                          I think it's not correct result!

                          Why?...

                          Regards,
                          Mucip:)

                          1 Reply Last reply
                          0
                          • MucipM Offline
                            MucipM Offline
                            Mucip
                            wrote on last edited by
                            #12

                            Hi,
                            I coppied all code from here in to VisualStudio cpp project and result is OK.

                            The problem is when I use this code in Qt and I don't know why?..

                            Regards,
                            Mucip:)

                            1 Reply Last reply
                            0
                            • MucipM Offline
                              MucipM Offline
                              Mucip
                              wrote on last edited by
                              #13

                              Hi again,
                              I coppied all code again in to Qt and add the below code in the top of the code.

                              BSTR resource = SysAllocString(L"ROOT\\CIMV2");
                                  CoUninitialize();
                              

                              Now it's OK. Thanks all.

                              aha_1980A 1 Reply Last reply
                              1
                              • MucipM Mucip

                                Hi again,
                                I coppied all code again in to Qt and add the below code in the top of the code.

                                BSTR resource = SysAllocString(L"ROOT\\CIMV2");
                                    CoUninitialize();
                                

                                Now it's OK. Thanks all.

                                aha_1980A Offline
                                aha_1980A Offline
                                aha_1980
                                Lifetime Qt Champion
                                wrote on last edited by
                                #14

                                @Mucip said in How to get the motherboard serial number on Win machine?:

                                Now it's OK. Thanks all.

                                Then please mark as SOLVED. Thanks!

                                Qt has to stay free or it will die.

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved