• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1737
  • Last Modified:

Get Info windows user log on

I want to get information about windows user log on.... I know that the function GetUserName I get Windows User Name, but I´d like to get User Id and Session(for example: Console).

Do know any function similar to GetUseName that I can use to get User Id and Session?

Thanks.
0
cdtcol
Asked:
cdtcol
  • 2
1 Solution
 
fcarraiCommented:
To get the user id:

string Userid = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

For the session ID you can access the kernel API:

using System.Runtime.InteropServices;

        [DllImport("kernel32.dll")]
        private static extern int WTSGetActiveConsoleSessionId();  
0
 
cdtcolAuthor Commented:
Thanks for you answer-...

Does WTSGetActiveConsoleSessionId() work only for Windows Terminal Server?

do you know any solution for Visual C++ 6.0?

Thanks,


0
 
fcarraiCommented:
It shoudl work also with Citrix products. The WTSGetActiveConsoleSessionId() is part of the Windows kernel, so can be used also with non .NET apps.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now