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. QSysInfo::machineUniqueId() empty on Windows

QSysInfo::machineUniqueId() empty on Windows

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 4 Posters 6.6k Views
  • 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.
  • M Offline
    M Offline
    Marek
    wrote on 21 Jun 2018, 15:28 last edited by
    #1

    Hi
    Since Qt 5.11 there is function QSysInfo::machineUniqueId() which should return unique ID per machine (eg. processor number, mainboard number), on Linux it works, on Windows 10 it returns empty string (tested on Win 10 and Qt 5.11.1).
    Is this as it should be ? Can't get this machineUniqueId on Windows, or is this some bug?

    Best Regards
    Marek

    J 1 Reply Last reply 21 Jun 2018, 15:55
    0
    • M Marek
      21 Jun 2018, 15:28

      Hi
      Since Qt 5.11 there is function QSysInfo::machineUniqueId() which should return unique ID per machine (eg. processor number, mainboard number), on Linux it works, on Windows 10 it returns empty string (tested on Win 10 and Qt 5.11.1).
      Is this as it should be ? Can't get this machineUniqueId on Windows, or is this some bug?

      Best Regards
      Marek

      J Offline
      J Offline
      JonB
      wrote on 21 Jun 2018, 15:55 last edited by JonB
      #2

      @Marek
      I suspect this is because from docs:

      QByteArray QSysInfo::machineUniqueId()
      See also machineHostName() and bootUniqueId().

      and

      QByteArray QSysInfo::bootUniqueId()
      This function is currently only implemented for Linux and Apple operating systems.
      See also machineUniqueId().

      EDIT: Hmm, maybe not. From https://code.woboq.org/qt5/qtbase/src/corelib/global/qglobal.cpp.html#_ZN8QSysInfo15machineUniqueIdEv I see:

      #elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT) 
          // Let's poke at the registry 
          HKEY key = NULL; 
          if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ, &key) 
                  == ERROR_SUCCESS) { 
              wchar_t buffer[UuidStringLen + 1]; 
              DWORD size = sizeof(buffer); 
              bool ok = (RegQueryValueEx(key, L"MachineGuid", NULL, NULL, (LPBYTE)buffer, &size) == 
                         ERROR_SUCCESS); 
              RegCloseKey(key); 
              if (ok) 
                  return QStringView(buffer, (size - 1) / 2).toLatin1(); 
          } 
      #endif 
          return QByteArray(); 
      

      So, assuming not Q_OS_WINRT (whatever that is for), do you have that registry value defined, and readable to your app?

      M 1 Reply Last reply 21 Jun 2018, 16:33
      1
      • J JonB
        21 Jun 2018, 15:55

        @Marek
        I suspect this is because from docs:

        QByteArray QSysInfo::machineUniqueId()
        See also machineHostName() and bootUniqueId().

        and

        QByteArray QSysInfo::bootUniqueId()
        This function is currently only implemented for Linux and Apple operating systems.
        See also machineUniqueId().

        EDIT: Hmm, maybe not. From https://code.woboq.org/qt5/qtbase/src/corelib/global/qglobal.cpp.html#_ZN8QSysInfo15machineUniqueIdEv I see:

        #elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT) 
            // Let's poke at the registry 
            HKEY key = NULL; 
            if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ, &key) 
                    == ERROR_SUCCESS) { 
                wchar_t buffer[UuidStringLen + 1]; 
                DWORD size = sizeof(buffer); 
                bool ok = (RegQueryValueEx(key, L"MachineGuid", NULL, NULL, (LPBYTE)buffer, &size) == 
                           ERROR_SUCCESS); 
                RegCloseKey(key); 
                if (ok) 
                    return QStringView(buffer, (size - 1) / 2).toLatin1(); 
            } 
        #endif 
            return QByteArray(); 
        

        So, assuming not Q_OS_WINRT (whatever that is for), do you have that registry value defined, and readable to your app?

        M Offline
        M Offline
        Marek
        wrote on 21 Jun 2018, 16:33 last edited by
        #3

        @JonB I will try this now, but since RegOpenKeyEx is from Win api not Qt which lib should I link to and include headers?

        Thanks,
        Marek

        J 1 Reply Last reply 21 Jun 2018, 16:35
        0
        • M Marek
          21 Jun 2018, 16:33

          @JonB I will try this now, but since RegOpenKeyEx is from Win api not Qt which lib should I link to and include headers?

          Thanks,
          Marek

          J Offline
          J Offline
          JonB
          wrote on 21 Jun 2018, 16:35 last edited by JonB
          #4

          @Marek
          Not sure what you mean, but I did not mean compile anything! I meant: look at that code, and go look in your registry to see whether you even have that entry sitting there or not, because that is the code Qt will be executing for you. I can see that key value under my Win 8 (so I would expect the Qt call to work), maybe it isn't there on your machine in Win 10, or (unlikely?) your Qt app process has no permission to read it from the registry?

          M 1 Reply Last reply 21 Jun 2018, 16:45
          0
          • J JonB
            21 Jun 2018, 16:35

            @Marek
            Not sure what you mean, but I did not mean compile anything! I meant: look at that code, and go look in your registry to see whether you even have that entry sitting there or not, because that is the code Qt will be executing for you. I can see that key value under my Win 8 (so I would expect the Qt call to work), maybe it isn't there on your machine in Win 10, or (unlikely?) your Qt app process has no permission to read it from the registry?

            M Offline
            M Offline
            Marek
            wrote on 21 Jun 2018, 16:45 last edited by
            #5

            @JonB I have compiled this into app and it returns empty string, I think because I can see Q_OS_WINRT is set
            This windows is a bit slow...

            J 1 Reply Last reply 21 Jun 2018, 16:50
            0
            • M Marek
              21 Jun 2018, 16:45

              @JonB I have compiled this into app and it returns empty string, I think because I can see Q_OS_WINRT is set
              This windows is a bit slow...

              J Offline
              J Offline
              JonB
              wrote on 21 Jun 2018, 16:50 last edited by JonB
              #6

              @Marek
              http://qt.apidoc.info/5.2.0/qtcore/qtglobal.html#Q_OS_WINRT:

              Defined for Windows Runtime (Windows Store apps) on Windows 8, Windows RT, and Windows Phone 8.

              Is your Qt compiled for Win 10 "Windows Store app" ??

              M 1 Reply Last reply 21 Jun 2018, 16:51
              0
              • J JonB
                21 Jun 2018, 16:50

                @Marek
                http://qt.apidoc.info/5.2.0/qtcore/qtglobal.html#Q_OS_WINRT:

                Defined for Windows Runtime (Windows Store apps) on Windows 8, Windows RT, and Windows Phone 8.

                Is your Qt compiled for Win 10 "Windows Store app" ??

                M Offline
                M Offline
                Marek
                wrote on 21 Jun 2018, 16:51 last edited by
                #7

                @JonB No I'm using QtIFW to create installer

                J 1 Reply Last reply 21 Jun 2018, 16:53
                0
                • M Marek
                  21 Jun 2018, 16:51

                  @JonB No I'm using QtIFW to create installer

                  J Offline
                  J Offline
                  JonB
                  wrote on 21 Jun 2018, 16:53 last edited by
                  #8

                  @Marek

                  • Recheck your claim "I think because I can see Q_OS_WINRT is set", because that doesn't sound likely to me?
                  • Look in your registry to see what you have for the key entry referenced in the code?
                  M 1 Reply Last reply 21 Jun 2018, 16:54
                  0
                  • J JonB
                    21 Jun 2018, 16:53

                    @Marek

                    • Recheck your claim "I think because I can see Q_OS_WINRT is set", because that doesn't sound likely to me?
                    • Look in your registry to see what you have for the key entry referenced in the code?
                    M Offline
                    M Offline
                    Marek
                    wrote on 21 Jun 2018, 16:54 last edited by
                    #9

                    @JonB Yeah, I have downloaded some tool for registry and I'm checking, will report

                    J 1 Reply Last reply 21 Jun 2018, 16:55
                    0
                    • M Marek
                      21 Jun 2018, 16:54

                      @JonB Yeah, I have downloaded some tool for registry and I'm checking, will report

                      J Offline
                      J Offline
                      JonB
                      wrote on 21 Jun 2018, 16:55 last edited by JonB
                      #10

                      @Marek
                      You don't need to download anything, you already have REGEDIT! :)

                      M 2 Replies Last reply 21 Jun 2018, 16:57
                      0
                      • J JonB
                        21 Jun 2018, 16:55

                        @Marek
                        You don't need to download anything, you already have REGEDIT! :)

                        M Offline
                        M Offline
                        Marek
                        wrote on 21 Jun 2018, 16:57 last edited by
                        #11

                        @JonB REGEDIT inside Win ? Sorry I don't work usally on Windows. I have downloaded some regmagik and I can see that Microsoft\Cryptography hasn't any keys only some branches.

                        J 1 Reply Last reply 21 Jun 2018, 17:01
                        0
                        • J JonB
                          21 Jun 2018, 16:55

                          @Marek
                          You don't need to download anything, you already have REGEDIT! :)

                          M Offline
                          M Offline
                          Marek
                          wrote on 21 Jun 2018, 16:59 last edited by
                          #12

                          @JonB I have searched through the registry and there is no MachineGuid in reg

                          1 Reply Last reply
                          0
                          • M Marek
                            21 Jun 2018, 16:57

                            @JonB REGEDIT inside Win ? Sorry I don't work usally on Windows. I have downloaded some regmagik and I can see that Microsoft\Cryptography hasn't any keys only some branches.

                            J Offline
                            J Offline
                            JonB
                            wrote on 21 Jun 2018, 17:01 last edited by
                            #13

                            @Marek
                            Yeah, everybody knows that Windows comes with REGEDIT for examining the Registry! :)

                            If you don't have HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid (I do), that function is not going to return anything on your machine. That's all I know.

                            M 2 Replies Last reply 21 Jun 2018, 17:03
                            0
                            • J JonB
                              21 Jun 2018, 17:01

                              @Marek
                              Yeah, everybody knows that Windows comes with REGEDIT for examining the Registry! :)

                              If you don't have HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid (I do), that function is not going to return anything on your machine. That's all I know.

                              M Offline
                              M Offline
                              Marek
                              wrote on 21 Jun 2018, 17:03 last edited by
                              #14

                              @JonB anyway thanks for help, I really have Q_OS_WINRT set thats why this code returned empty string first time I have compiled

                              J 1 Reply Last reply 21 Jun 2018, 17:06
                              0
                              • M Marek
                                21 Jun 2018, 17:03

                                @JonB anyway thanks for help, I really have Q_OS_WINRT set thats why this code returned empty string first time I have compiled

                                J Offline
                                J Offline
                                JonB
                                wrote on 21 Jun 2018, 17:06 last edited by JonB
                                #15

                                @Marek
                                Well actually that sounds more reasonable as an explanation, because I think the registry entry really is there under all Windows.

                                Now your question becomes: "why does the Qt I am using seem to have been compiled with Q_OS_WINRT defined, because I would have thought it should not?".

                                I am not a Qt expert: you would need someone like @SGaist to see this, look through my understanding of what must be going on, and explain.

                                M 1 Reply Last reply 21 Jun 2018, 17:08
                                0
                                • J JonB
                                  21 Jun 2018, 17:06

                                  @Marek
                                  Well actually that sounds more reasonable as an explanation, because I think the registry entry really is there under all Windows.

                                  Now your question becomes: "why does the Qt I am using seem to have been compiled with Q_OS_WINRT defined, because I would have thought it should not?".

                                  I am not a Qt expert: you would need someone like @SGaist to see this, look through my understanding of what must be going on, and explain.

                                  M Offline
                                  M Offline
                                  Marek
                                  wrote on 21 Jun 2018, 17:08 last edited by
                                  #16

                                  @JonB does this matter if on my win 10 there is o MachineGuid key ?
                                  I'm checking something, I'm using MinGW 32 bit, https://github.com/gentoo90/winreg-rs/issues/10 try to compile with msvc2017 64bit

                                  J 1 Reply Last reply 21 Jun 2018, 17:27
                                  0
                                  • J JonB
                                    21 Jun 2018, 17:01

                                    @Marek
                                    Yeah, everybody knows that Windows comes with REGEDIT for examining the Registry! :)

                                    If you don't have HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid (I do), that function is not going to return anything on your machine. That's all I know.

                                    M Offline
                                    M Offline
                                    Marek
                                    wrote on 21 Jun 2018, 17:20 last edited by
                                    #17

                                    @JonB OK, success, Thanks for your help ;)
                                    so windows can provide "virtual" registry for 32 bit applications and this registry does not have MachineGuid. I have compiled with msvc2017 64Bit and it works. I can call it a day ;)

                                    Best,
                                    Marek

                                    1 Reply Last reply
                                    1
                                    • M Marek
                                      21 Jun 2018, 17:08

                                      @JonB does this matter if on my win 10 there is o MachineGuid key ?
                                      I'm checking something, I'm using MinGW 32 bit, https://github.com/gentoo90/winreg-rs/issues/10 try to compile with msvc2017 64bit

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 21 Jun 2018, 17:27 last edited by JonB
                                      #18

                                      @Marek
                                      Yes it can. It's all to do with the Wow6432Node key:

                                      Yes, for 32-bit software 64-bit OS will substitute HKLM\SOFTWARE\ path with HKLM\SOFTWARE\Wow6432Node\. So you were trying to read HKLM\SOFTWARE\Wow6432Node\Microsoft\Cryptography\MachineGuid which doesn't exist.

                                      You did not say in your question that any 32-bitted-ness was involved at your side, I assumed all 64-bit, else I would have said about needing to change where you look in the registry :)

                                      M 1 Reply Last reply 21 Jun 2018, 17:48
                                      2
                                      • J JonB
                                        21 Jun 2018, 17:27

                                        @Marek
                                        Yes it can. It's all to do with the Wow6432Node key:

                                        Yes, for 32-bit software 64-bit OS will substitute HKLM\SOFTWARE\ path with HKLM\SOFTWARE\Wow6432Node\. So you were trying to read HKLM\SOFTWARE\Wow6432Node\Microsoft\Cryptography\MachineGuid which doesn't exist.

                                        You did not say in your question that any 32-bitted-ness was involved at your side, I assumed all 64-bit, else I would have said about needing to change where you look in the registry :)

                                        M Offline
                                        M Offline
                                        Marek
                                        wrote on 21 Jun 2018, 17:48 last edited by
                                        #19

                                        @JonB I did not supposed it matters, frankly I prefer to use MinGW (old habits maybe) and I didn't see Qt 5.11 for MinGW 64bit.
                                        @CoreyAnderson how this HP printer support is related to Qt or even Windows 10, I don't get it, you mean bug in Windows that it does not provide key for 32bit apps ?

                                        J 1 Reply Last reply 21 Jun 2018, 17:59
                                        0
                                        • M Marek
                                          21 Jun 2018, 17:48

                                          @JonB I did not supposed it matters, frankly I prefer to use MinGW (old habits maybe) and I didn't see Qt 5.11 for MinGW 64bit.
                                          @CoreyAnderson how this HP printer support is related to Qt or even Windows 10, I don't get it, you mean bug in Windows that it does not provide key for 32bit apps ?

                                          J Offline
                                          J Offline
                                          JonB
                                          wrote on 21 Jun 2018, 17:59 last edited by JonB
                                          #20

                                          @Marek

                                          Ignore @CoreyAnderson 's post, he is just advertising his hyperlink! It's a scam.

                                          You can use a 64-bit compiler with no issue. If you want to use a 32-bit compiler, you will have to do some work.

                                          M 1 Reply Last reply 21 Jun 2018, 18:06
                                          0

                                          1/28

                                          21 Jun 2018, 15:28

                                          • Login

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