To the main page...The list of my products...Some texts...Sample applications, tips, tricks...If you need support...
 

 
How to get the interactive user's name from service
Published 27.07.2000
It is compatible with...
Win 95 compatible Win 98 compatible Win NT compatible Windows 2000 compatible Delphi 3 compatible Delphi 4 compatible Delphi 5 compatible  

The compiled and ready for tests version of this example is available here (zip, 256Kb). "How to use" instructions are inside.

It is well known that the GetUserName API function should be used to get the name of current user. For Windows NT it means the name of user whose profile was used to create and run the process.

Sometimes service application needs to know the name of the currently logged on user. The GetUserName will not help in this case because service usually starts in the specific account, and the Local System account is typical.

This example shows how to get this information from service. To get the name of interactive user it is necessary to perform the following operations:

  1. Ensure that the user is logged in;
  2. Obtain the handle of process that runs in the context of interactive user;
  3. Get the user's SID from the token of this process;
  4. Retrieve the user's name from the SID.

The full source code of this example is here (zip, 3.5Kb)

Index | Step 1 | Step 2 | Step 3 | Step 4 |>>
Add your comment | Read comments


 
© 1998-2001 Alexey Dynnikov
My ICQ # is 18267212