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. Qt app and Active directory?
Forum Updated to NodeBB v4.3 + New Features

Qt app and Active directory?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 5 Posters 7.2k Views 2 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.
  • xopheriraX Offline
    xopheriraX Offline
    xopherira
    wrote on last edited by
    #1

    I have a Qt app that I need to default the current users email. Is there a way in Qt to get the username from active directory in order to use as a default? Has anyone had experience with this?

    raven-worxR 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      This is platform dependant. What OS are you using?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • xopheriraX Offline
        xopheriraX Offline
        xopherira
        wrote on last edited by
        #3

        I am using windows 7 with Qt 5, minGw build kit.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          You can use QSettings to register your program in the keys described here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd203067(v=vs.85).aspx

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • xopheriraX xopherira

            I have a Qt app that I need to default the current users email. Is there a way in Qt to get the username from active directory in order to use as a default? Has anyone had experience with this?

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @xopherira said in Qt app and Active directory?:

            Is there a way in Qt to get the username from active directory in order to use as a default?

            Not directly in via Qt. But maybe this helps.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            2
            • Paul ColbyP Offline
              Paul ColbyP Offline
              Paul Colby
              wrote on last edited by
              #6

              You could try GetUserNameEx with NameUserPrincipal... not sure if AD populates that in your scenario, but worth a try?

              1 Reply Last reply
              2
              • veryqtpersonV Offline
                veryqtpersonV Offline
                veryqtperson
                wrote on last edited by
                #7

                There's no API for AD in Qt libraries, afaik. One way to achieve what you want though, is to call ldifde with QProcess and get the info from its output :)

                1 Reply Last reply
                1
                • xopheriraX Offline
                  xopheriraX Offline
                  xopherira
                  wrote on last edited by
                  #8

                  Thanks to all, I will get one of these to work!

                  1 Reply Last reply
                  0
                  • xopheriraX Offline
                    xopheriraX Offline
                    xopherira
                    wrote on last edited by
                    #9

                    For those interested in my solution, here's the code.

                       TCHAR Username[UNLEN+1];
                        DWORD nULen = UNLEN;
                        GetUserName(Username, &nULen);
                        QString adUserName = QString::fromWCharArray(Username);
                    
                    veryqtpersonV 1 Reply Last reply
                    0
                    • xopheriraX xopherira

                      For those interested in my solution, here's the code.

                         TCHAR Username[UNLEN+1];
                          DWORD nULen = UNLEN;
                          GetUserName(Username, &nULen);
                          QString adUserName = QString::fromWCharArray(Username);
                      
                      veryqtpersonV Offline
                      veryqtpersonV Offline
                      veryqtperson
                      wrote on last edited by
                      #10

                      GetUserName

                      But what library did you use?

                      Paul ColbyP 1 Reply Last reply
                      0
                      • xopheriraX Offline
                        xopheriraX Offline
                        xopherira
                        wrote on last edited by
                        #11

                        #include <Security.h>
                        #include <lmcons.h>
                        #include <Windows.h>

                        1 Reply Last reply
                        0
                        • veryqtpersonV veryqtperson

                          GetUserName

                          But what library did you use?

                          Paul ColbyP Offline
                          Paul ColbyP Offline
                          Paul Colby
                          wrote on last edited by
                          #12

                          @veryqtperson said:

                          GetUserName

                          But what library did you use?

                          Presumably he's referring to GetUserName, which is part of the Windows API (formerly known as "win32"). Obviously not portable, but that's presumably not an issue for @xopherira in this particular use case.

                          Cheers.

                          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