all groups > dotnet framework > february 2006 >
You're in the

dotnet framework

group:

Get current logged on user


RE: Get current logged on user Greg Young
2/28/2006 3:14:36 PM
dotnet framework:
I have dealt with a similar situation before ... I never got the actual
identity of the user but using

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/TermServ/wtsgetactiveconsolesessionid.asp
an
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/TermServ/wtsquerysessioninformation.asp

I was able to get the name of the user (including fast switching for
multiple users).

Cheers,

Greg

[quoted text, click to view]
Re: Get current logged on user Gabriel Magaña
2/28/2006 3:33:02 PM
Did you take into account remote desktop and/or terminal services? This
would mean that several users have valid session concurrently... How did
you deal with that screnario?


[quoted text, click to view]

Re: Get current logged on user William Stacey [MVP]
2/28/2006 9:44:26 PM
| 1. Start the service when a user logs on (i.e. service not active before
| logon)

You could use the ServiceControl control to start service when your app
starts. Or put your app in the Startup folder.

| 2. Determine the WindowsIdentity of the currently logged on user

private void button18_Click(object sender, EventArgs e)

{

WindowsIdentity wi = WindowsIdentity.GetCurrent();

Console.WriteLine("Current User: " + wi.Name);

foreach (IdentityReference ir in wi.Groups)

{

NTAccount acc = (NTAccount)ir.Translate(typeof(NTAccount));

Console.WriteLine("Member of: " + acc.Value);

}

}

Get current logged on user Niclas
2/28/2006 10:39:14 PM
Is it possible to configure a Windows Service to:

1. Start the service when a user logs on (i.e. service not active before
logon)

2. Determine the WindowsIdentity of the currently logged on user

Niclas

AddThis Social Bookmark Button