Search code examples
c++comdcom

How can I get the user name who invoked the method of COM server?


I have a COM server written in C++ running on some computer in a network. Clients may perform remote calls to it from the other computers. Can I determine the name of the user which make the call to the COM-methods from the methods itself?


Solution

  • You can accomplish this by calling CoImpersonateClient() from within a COM method. One you're impersonating, you can then call GetUserNameEx() to fetch the user name.