Solved

Getting the user details of a thread at runtime

Posted on 2011-02-14
3
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 250 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article discusses the Chain of Responsibility pattern, explaining What it is;Why it is; andHow it is At the end of this article, I hope you will be able to describe the use and benefits of Chain of Responsibility.  Backgrou…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

734 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