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
Solved

Getting the user details of a thread at runtime

Posted on 2011-02-14
3
256 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Find Visual Studio Tools 2 111
object oriented javascript web form 8 144
Better understanding on C++ Class serialization and formats 9 78
Header of docx file 17 115
The Fluent Interface Design Pattern You can use the Fluent Interface (http://en.wikipedia.org/wiki/Fluent_interface) design pattern to make your PHP code easier to read and maintain.  "Fluent Interface" is an object-oriented design pattern that r…
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 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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

860 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