473,686 Members | 2,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13226
I have not tried, but check it: P/Invoke call on GetSystemMetric s(0x1000).
Should return non-zero under Term. Services. 0, otherwise.

"Tim" <ti*@home.com > wrote in message
news:_Y******** *************@n ews20.bellgloba l.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******** *************@n ews20.bellgloba l.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.Session Id 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******@onlin e.excite.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
I have not tried, but check it: P/Invoke call on GetSystemMetric s(0x1000).
Should return non-zero under Term. Services. 0, otherwise.

"Tim" <ti*@home.com > wrote in message
news:_Y******** *************@n ews20.bellgloba l.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******** ********@TK2MSF TNGP11.phx.gbl. ..

"Tim" <ti*@home.com > wrote in message
news:_Y******** *************@n ews20.bellgloba l.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.Session Id 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 ProcessIdToSess ionId, something
like this will do:
[DllImport("Kern el32")
extern static int ProcessIdToSess ionId(int procId, out int sessId);

int procId = Process.getCurr entProcess().Id ;
int sessId = 0;

if(ProcessIdToS essionId(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******** *************@n ews20.bellgloba l.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******** ********@TK2MSF TNGP11.phx.gbl. ..
| >
| > "Tim" <ti*@home.com > wrote in message
| > news:_Y******** *************@n ews20.bellgloba l.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.Session Id 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("kern el32.dll")]
static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
pSessionId);
uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
uint sessId = 0;
if(ProcessIdToS essionId(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******** ******@TK2MSFTN GP15.phx.gbl...
That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
something
like this will do:
[DllImport("Kern el32")
extern static int ProcessIdToSess ionId(int procId, out int sessId);

int procId = Process.getCurr entProcess().Id ;
int sessId = 0;

if(ProcessIdToS essionId(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******** *************@n ews20.bellgloba l.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******** ********@TK2MSF TNGP11.phx.gbl. ..
| >
| > "Tim" <ti*@home.com > wrote in message
| > news:_Y******** *************@n ews20.bellgloba l.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.Session Id 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%******** *********@news2 0.bellglobal.co m...
Hi Wily,

I tried this

[DllImport("kern el32.dll")]
static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
pSessionId);
uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
uint sessId = 0;
if(ProcessIdToS essionId(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******** ******@TK2MSFTN GP15.phx.gbl...
That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
something
like this will do:
[DllImport("Kern el32")
extern static int ProcessIdToSess ionId(int procId, out int sessId);

int procId = Process.getCurr entProcess().Id ;
int sessId = 0;

if(ProcessIdToS essionId(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******** *************@n ews20.bellgloba l.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******** ********@TK2MSF TNGP11.phx.gbl. ..
| >
| > "Tim" <ti*@home.com > wrote in message
| > news:_Y******** *************@n ews20.bellgloba l.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.Session Id 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******** *********@news2 0.bellglobal.co m...
|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%******** *********@news2 0.bellglobal.co m...
| > Hi Wily,
| >
| > I tried this
| >
| > [DllImport("kern el32.dll")]
| > static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
| > pSessionId);
| > uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
| > uint sessId = 0;
| > if(ProcessIdToS essionId(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******** ******@TK2MSFTN GP15.phx.gbl...
| >> That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
| >> something
| >> like this will do:
| >>
| >>
| >> [DllImport("Kern el32")
| >> extern static int ProcessIdToSess ionId(int procId, out int sessId);
| >>
| >> int procId = Process.getCurr entProcess().Id ;
| >> int sessId = 0;
| >>
| >> if(ProcessIdToS essionId(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******** *************@n ews20.bellgloba l.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******** ********@TK2MSF TNGP11.phx.gbl. ..
| >> | >
| >> | > "Tim" <ti*@home.com > wrote in message
| >> | > news:_Y******** *************@n ews20.bellgloba l.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.Session Id 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******** ********@TK2MSF TNGP12.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******** *********@news2 0.bellglobal.co m...
|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%******** *********@news2 0.bellglobal.co m...
| > Hi Wily,
| >
| > I tried this
| >
| > [DllImport("kern el32.dll")]
| > static extern bool ProcessIdToSess ionId(uint dwProcessId, out uint
| > pSessionId);
| > uint procId = System.Convert. ToUInt32(Proces s.GetCurrentPro cess().Id);
| > uint sessId = 0;
| > if(ProcessIdToS essionId(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******** ******@TK2MSFTN GP15.phx.gbl...
| >> That's right, on v1.1 you'll have to PInvoke ProcessIdToSess ionId,
| >> something
| >> like this will do:
| >>
| >>
| >> [DllImport("Kern el32")
| >> extern static int ProcessIdToSess ionId(int procId, out int sessId);
| >>
| >> int procId = Process.getCurr entProcess().Id ;
| >> int sessId = 0;
| >>
| >> if(ProcessIdToS essionId(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******** *************@n ews20.bellgloba l.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******** ********@TK2MSF TNGP11.phx.gbl. ..
| >> | >
| >> | > "Tim" <ti*@home.com > wrote in message
| >> | > news:_Y******** *************@n ews20.bellgloba l.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.Session Id property, if it's non zero it means
you
| >> are
| >> | > running in a TS session.
| >> | >
| >> | > Willy.
| >> | >
| >> | >
| >> |
| >> |
| >>
| >>
| >
| >
|
|

Jan 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
10221
by: Etienne Charland | last post by:
Hi, there is an application running on a remote desktop (under Citrix ICA, but the same problem applies for RDC or PC Anywhere). Now, I want to send keys to the remote application from a local app. I tried sending keys in VB with SendKeys, as well as using keybd_event API, but I'm not able to send any keys. It works very well for any local applications, but I can't pass the keys remotely. Is there any way to do it? Thanks! Etienne
5
45006
by: Morten | last post by:
How do I detect if a client socket is no longer connected to the listen tcp socket ? I have tried with (just an example): --------------------- Socket tcpSocket; while(tcpSocket.Connected)
0
1471
by: matvdl | last post by:
My asp.net application depends on obtaining allot of data from a remote application. This application is a bit of a monster and it is not an option to install it on the asp.net system. Note - the remote application is developed in vb6 Currently I have the application installed on a number of remote computers and use DCOM from asp.net to communicate with this application. All the calls to this remote application are generally kept to a...
4
3735
by: John Blair | last post by:
Hi, I would like my page_load event to detect if a session has timed out..is this possible? Thanks.
4
2809
by: Chris Johnson | last post by:
Hey all, I have a small app I have developed that periodically pings a list of server and returns their status. Given my environment I have setup the program such that a server can be down 4 minutes before I get an alert. My problem now is that is a server is rebooted, it will be back up before the 4 minute window and I will not be aware that it has rebooted. I am looking for a way (as an administrator, or not, if possible) to detect
1
4978
by: anonieko | last post by:
Problem When Remote Desktop to my main office machine, and when trying to connect to SQL Express, I was becoming increasingly frustrated with the following error: Error: 'Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.'
3
4518
by: gsherp | last post by:
I am trying to determine the ip address of a remote computer accessing my webpage. I do this to determine if the user if logged on elsewhere. If so, the server will reject actions from the previous location and log the user in from the new location. However, since all the computers are behind the gateway, I use $_SERVER; and only get the static ip of the gateway. Is there anyway to find out which specific computer is trying to login? If...
5
17743
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager with the path "\\ 192.168.2.2\temp" (where temp is a shared directory on server \\192.168.2.2), windows prompts for a User Name and password of a user who has permission on that computer to access that directory. If I enter valid details, the...
4
7179
by: goscottie | last post by:
I used submodal as my popup window. With some tweaks, it working great in my app. However, I can't find a way to detect session timeout in the popup window. The app is a form based authentication so the default.aspx page will show up in the popup. So I'm looking into several options. 1. detect session timeout in javascript so that I prevent the popup from even happening. I can simply redirect or post to itself so that the calling...
0
9057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8942
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8776
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8781
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6444
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2210
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1943
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.