471,318 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Detect Remote RDP Session??

Tim
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
Jan 7 '06 #1
9 12980
I have not tried, but check it: P/Invoke call on GetSystemMetrics(0x1000).
Should return non-zero under Term. Services. 0, otherwise.

"Tim" <ti*@home.com> wrote in message
news:_Y*********************@news20.bellglobal.com ...
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

Jan 7 '06 #2

"Tim" <ti*@home.com> wrote in message
news:_Y*********************@news20.bellglobal.com ...
| 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.
Jan 7 '06 #3
Tim
Thanks for the reply Siva, I don't suppose you could give me some more
information. I am not sure how to proceed. I would appreciate some actual
code if you can.

Thanks

Tim
"Siva M" <sh******@online.excite.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
I have not tried, but check it: P/Invoke call on GetSystemMetrics(0x1000).
Should return non-zero under Term. Services. 0, otherwise.

"Tim" <ti*@home.com> wrote in message
news:_Y*********************@news20.bellglobal.com ...
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

Jan 8 '06 #4
Tim
I think this only works for .Net 2.0. I am using 1.1 still...

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

"Tim" <ti*@home.com> wrote in message
news:_Y*********************@news20.bellglobal.com ...
| 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.

Jan 8 '06 #5
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.

"Tim" <ti*@home.com> wrote in message
news:YR*********************@news20.bellglobal.com ...
|I think this only works for .Net 2.0. I am using 1.1 still...
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:%2****************@TK2MSFTNGP11.phx.gbl...
| >
| > "Tim" <ti*@home.com> wrote in message
| > news:_Y*********************@news20.bellglobal.com ...
| > | 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.
| >
| >
|
|
Jan 8 '06 #6
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

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
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.

"Tim" <ti*@home.com> wrote in message
news:YR*********************@news20.bellglobal.com ...
|I think this only works for .Net 2.0. I am using 1.1 still...
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:%2****************@TK2MSFTNGP11.phx.gbl...
| >
| > "Tim" <ti*@home.com> wrote in message
| > news:_Y*********************@news20.bellglobal.com ...
| > | 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.
| >
| >
|
|

Jan 8 '06 #7
Tim
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/de...osessionid.asp

Tim

"Tim" <ti*@home.com> wrote in message
news:N%*****************@news20.bellglobal.com...
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

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
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.

"Tim" <ti*@home.com> wrote in message
news:YR*********************@news20.bellglobal.com ...
|I think this only works for .Net 2.0. I am using 1.1 still...
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:%2****************@TK2MSFTNGP11.phx.gbl...
| >
| > "Tim" <ti*@home.com> wrote in message
| > news:_Y*********************@news20.bellglobal.com ...
| > | 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.
| >
| >
|
|


Jan 8 '06 #8
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.

"Tim" <ti*@home.com> wrote in message
news:K5*****************@news20.bellglobal.com...
|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/de...osessionid.asp
|
| Tim
|
| "Tim" <ti*@home.com> wrote in message
| news:N%*****************@news20.bellglobal.com...
| > 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
| >
| > "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| > news:ez**************@TK2MSFTNGP15.phx.gbl...
| >> 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.
| >>
| >>
| >>
| >> "Tim" <ti*@home.com> wrote in message
| >> news:YR*********************@news20.bellglobal.com ...
| >> |I think this only works for .Net 2.0. I am using 1.1 still...
| >> |
| >> | "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| >> | news:%2****************@TK2MSFTNGP11.phx.gbl...
| >> | >
| >> | > "Tim" <ti*@home.com> wrote in message
| >> | > news:_Y*********************@news20.bellglobal.com ...
| >> | > | 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.
| >> | >
| >> | >
| >> |
| >> |
| >>
| >>
| >
| >
|
|
Jan 8 '06 #9
Tim
Hi Willy (sorry for mis-spelling your name before),

Is there any way to tell if it is a remote desktop session that is running
on an XP machine or something that is not a server with a proper terminal
services session?

Tim
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.

"Tim" <ti*@home.com> wrote in message
news:K5*****************@news20.bellglobal.com...
|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/de...osessionid.asp
|
| Tim
|
| "Tim" <ti*@home.com> wrote in message
| news:N%*****************@news20.bellglobal.com...
| > 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
| >
| > "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| > news:ez**************@TK2MSFTNGP15.phx.gbl...
| >> 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.
| >>
| >>
| >>
| >> "Tim" <ti*@home.com> wrote in message
| >> news:YR*********************@news20.bellglobal.com ...
| >> |I think this only works for .Net 2.0. I am using 1.1 still...
| >> |
| >> | "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in
message
| >> | news:%2****************@TK2MSFTNGP11.phx.gbl...
| >> | >
| >> | > "Tim" <ti*@home.com> wrote in message
| >> | > news:_Y*********************@news20.bellglobal.com ...
| >> | > | 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.
| >> | >
| >> | >
| >> |
| >> |
| >>
| >>
| >
| >
|
|

Jan 9 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Etienne Charland | last post: by
5 posts views Thread by Morten | last post: by
reply views Thread by matvdl | last post: by
4 posts views Thread by Chris Johnson | last post: by
5 posts views Thread by =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post: by
4 posts views Thread by goscottie | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.