Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting the user details of a thread at runtime

Posted on 2011-02-14
3
Medium Priority
?
269 Views
Last Modified: 2012-05-11
Hi,

I am having a C++ based COM application which is a multi-threaded application. A number of threads are spawned from main process, I would like to retrieve the user details of a thread at run-time, which functions should be used.

Thanks,
Saravanan
0
Comment
Question by:sarantm
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 1000 total points
ID: 34888137
Hi sarantm,

as far as I understand you want to get info about the user who is the owner of a thread, right?

If so you can use 'OpenThreadToken' to retrieve the thread's 'access token' - with this you can get 'GetTokenInformation' to retrieve further information, i.e. 'TokenOwner' - this will return an SID which can be used to retrieve the user's name with 'LookupAccountSid'.

Hope that helps,

ZOPPO
0
 

Author Comment

by:sarantm
ID: 35006603
Hello ZOPPO,

I used GetUserNameEx function to retrieve user name and domain of given thread. This is much more easier than your approach.

What is advantage over your approach and mine.

Tnx,
Saravanan
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 35007099
Well, I posted the above comment since from your question it wasn't really clear what exactly you need.

The 'GetUserNameEx' returns info about the calling thread - my suggestion can be used to retrieve info about any running thread (as long as the calling thread has permissions to query info about that thread) - so, you could even i.e. use it to enumerate through all threads running on a machine and determine the user who started these threads.

If you just need the info within the running thread for sure 'GetUserNameEx' is much easier ...
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question