Reputation: 61
As you can see in the tab user of the windows task manager, there are 5 columns :
User ID Status Client Name Session
Mike 1 Active Console
I have used this to get the session id :
System.Diagnostics.Process.GetCurrentProcess().SessionId.ToString();
I want to know the session name to see if it is console or remote desktop or etc.
private string getsessionname()
{
// function to get session name
}
if(getsessionname=="console")
{
// do staff1
}
else
{
// do staff2
}
thanks.
Upvotes: 1
Views: 3533
Reputation: 239636
Rather than getting the session name and then testing for certain values, are you not just looking for SystemInformation.TerminalServerSession
?
Gets a value indicating whether the calling process is associated with a Terminal Services client session.
E.g.:
using System.Windows.Forms;
...
if(SystemInformation.TerminalServerSession)
{
// do stuff where the user is using remote desktop
}
else
{
// user is connected locally, e.g. the console
}
Upvotes: 1
Reputation: 294197
There is no managed API. One way is to use the native API via P-Invoke, see Retrieving Logon Session Information. But a much easier way is to use WMI and query the Win32_LogonSession object.
Upvotes: 0