get current user/domain

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

does anyone know how to find out the logged in user with domain in vc++ ?

Thanks for help
Michael
 
does anyone know how to find out the logged in user with domain in vc++ ?

AppDomain::CurrentDomain->SetPrincipalPolicy(PrincipalPolicy::WindowsPrincipal);
WindowsPrincipal^ user =
safe_cast<WindowsPrincipal^>(Thread::CurrentPrincipal);

Console::WriteLine(user->Identity->Name);


Well, this will return the user information according to the security
context of the current thread ... i.e. you will get the user information
under which the current thread runs. Which is most likely what you wanna
have.

Won't work if you call this from a different security context, e.g.
inside a windows service application running under one of the system
accounts ...
 
does anyone know how to find out the logged in user with domain in vc++ ?

the simplest method is probably to use
GetUserNameEx
it allows you to get different name formats that represent the current user.
the NT4 compatible format is of the form domain\user. you should be able to
parse this string without much problems to extract user name and domain.

another approach that uses the platform authentication functions can be
found in knowledgebase article Q111544:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/enu_kbwin32sdk/en-us/win32sdk/Q111544.htm

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
thank you both for help.
I'm working with the GetUserNameEx-function, it works great.

Best Regards
Michael
 
Back
Top