Solved

Getting the user details of a thread at runtime

Posted on 2011-02-14
3
253 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 30

Accepted Solution

by:
Zoppo earned 250 total points
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

One of the most frequent problems a "newbie" developer may encounter is having to deal with different data formats. One for all: THE DATE We, as humans, need to "see" a date and then interpret it (much of the times this is an automatic operation)…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now