Solved Qt app and Active directory?
-
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?
-
This is platform dependant. What OS are you using?
-
I am using windows 7 with Qt 5, minGw build kit.
-
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
-
@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.
-
You could try GetUserNameEx with NameUserPrincipal... not sure if AD populates that in your scenario, but worth a try?
-
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 :)
-
Thanks to all, I will get one of these to work!
-
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);
-
GetUserName
But what library did you use?
-
#include <Security.h>
#include <lmcons.h>
#include <Windows.h> -
@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.