Windows client OS's don't run real TS sessions, they use TS technology to
present a remote desktop session (single session only), guess that's the
reason why 0 is returned.
Willy.
|I think I may have found the problem; the 'server' I am using is a WinXP
Pro
| machine... does this mean it will not work? MSDN documentation;
|
http://msdn.microsoft.com/library/d...us/termserv/termserv/processidtosessionid.asp
|
| Tim
|
| | > Hi Wily,
| >
| > I tried this
| >
| > [DllImport("kernel32.dll")]
| > static extern bool ProcessIdToSessionId(uint dwProcessId, out uint
| > pSessionId);
| > uint procId = System.Convert.ToUInt32(Process.GetCurrentProcess().Id);
| > uint sessId = 0;
| > if(ProcessIdToSessionId(procId, out sessId))
| > {
| > if (sessId == 0)
| > {
| > // no TS
| > }
| > else
| > {
| > // in TS
| > }
| > }
| >
| > but it is 0 for remote logins... Any other ideas??
| >
| > Tim
| >
| > | >> That's right, on v1.1 you'll have to PInvoke ProcessIdToSessionId,
| >> something
| >> like this will do:
| >>
| >>
| >> [DllImport("Kernel32")
| >> extern static int ProcessIdToSessionId(int procId, out int sessId);
| >>
| >> int procId = Process.getCurrentProcess().Id;
| >> int sessId = 0;
| >>
| >> if(ProcessIdToSessionId(procId, out sessId) != 0)
| >> {
| >> if (sessId == 0)
| >> // no TS
| >> else
| >> // in TS
| >> }
| >> else
| >> // API call failed
| >>
| >> Willy.
| >>
| >>
| >>
| >> | >> |I think this only works for .Net 2.0. I am using 1.1 still...
| >> |
message
| >> | | >> | >
| >> | > | >> | > | Hi Guys,
| >> | > |
| >> | > | I was wondering if there is a way to detect from with a C# app
if
| >> it
| >> is
| >> | > | being started in a remote session? i.e. someone has connected
via
| >> remote
| >> | > | desktop or terminal services...
| >> | > |
| >> | > | Thanks
| >> | > |
| >> | > | Tim
| >> | > |
| >> | > |
| >> | >
| >> | > Check the Process.SessionId property, if it's non zero it means
you
| >> are
| >> | > running in a TS session.
| >> | >
| >> | > Willy.
| >> | >
| >> | >
| >> |
| >> |
| >>
| >>
| >
| >
|
|