Get Username and Domain in C++ [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this questionBeen looking around a little bit and I have found some code to do this but it did not work...maybe my google skills aren't great but my question is....
Can anyone point me in the right direction of how to retrieve the logged on users username and the domain that they are a part of in C++. I am expanding upon a windows forms application. I am working in Visual Studio 2008
Link or code are welcome.
Thank you
[EDIT] I am looking for something like this开发者_如何学Go http://www.ehow.com/how_5169653_user-address-microsoft-visual-sharp.html
Besides the great link goths sent, you may try this for username:
TCHAR username[UNLEN + 1];
DWORD size = UNLEN + 1;
GetUserName((TCHAR*)username, &size);
I'm using Visual Studio Express 2012 (on Windows 7).
Username in a string :
void UserName(string *x){
char username[UNLEN + 1];
DWORD size = UNLEN + 1;
GetUserName(username, &size);
string transition(username);*x=transition;}
//use this synthax in main : string username;UserName(&username);
PS: don't forget these libraries :
#include <windows.h>
#include <Lmcons.h>
#include <string>
精彩评论