Discussion:
How to test if RemoteDesktop still connected from c# Options
(too old to reply)
l***@googlemail.com
2007-07-26 10:56:56 UTC
Permalink
I am trying to write an app in c# that monitors open RDCs and warns
me
if a connection goes down. I tried looking for ip address in
TaskManager list - which works, it can see difference between a RCD
window that has been logged into and one that has been cancelled (by
user). However, if connection is lost due to internet - I am not able
to look for anything that tells me this.

If anyone can think of a way that I can test whether a connection if
still up an running - I would be greateful. Obviously, I can tell on
the host side, but I want this to be from the side that initiated the
RDC.


Many thanks,


Lawrence
TP
2007-07-27 18:53:38 UTC
Permalink
Hi Lawrence,

You can wrap the Remote Desktop activex and then respond
to the various events as needed. Instead of connecting using
the regular RD client you would use your program to connect
instead.

-TP
Post by l***@googlemail.com
I am trying to write an app in c# that monitors open RDCs and warns
me
if a connection goes down. I tried looking for ip address in
TaskManager list - which works, it can see difference between a RCD
window that has been logged into and one that has been cancelled (by
user). However, if connection is lost due to internet - I am not able
to look for anything that tells me this.
If anyone can think of a way that I can test whether a connection if
still up an running - I would be greateful. Obviously, I can tell on
the host side, but I want this to be from the side that initiated the
RDC.
Many thanks,
Lawrence
l***@googlemail.com
2007-07-30 10:21:38 UTC
Permalink
Post by TP
Hi Lawrence,
You can wrap the Remote Desktop activex and then respond
to the various events as needed. Instead of connecting using
the regular RD client you would use your program to connect
instead.
-TP
Post by l***@googlemail.com
I am trying to write an app in c# that monitors open RDCs and warns
me
if a connection goes down. I tried looking for ip address in
TaskManager list - which works, it can see difference between a RCD
window that has been logged into and one that has been cancelled (by
user). However, if connection is lost due to internet - I am not able
to look for anything that tells me this.
If anyone can think of a way that I can test whether a connection if
still up an running - I would be greateful. Obviously, I can tell on
the host side, but I want this to be from the side that initiated the
RDC.
Many thanks,
Lawrence- Hide quoted text -
- Show quoted text -
TP,

Could you give me, or point me to a link that demonstrates what you
mean by 'wrap' please.

Thanks for responding,

Lawrence
TP
2007-07-30 13:28:05 UTC
Permalink
Hi Lawrence,

You need to add the Microsoft RDP Client Control to a
form--it is a COM Component. Then you can set its
properties, call its methods, and respond to its events.

For example, after you have the control on the form,
you could put a button with code to perform the
connection:

private void button1_Click(object sender, EventArgs e)
{
axMsRdpClient31.Server = "servername";
axMsRdpClient31.Connect();
}

You will also want to respond to the various events as
your needs dictate such as OnDisconnected.

Documentation of the methods, properties, and events are
up on MSDN.

-TP
Post by l***@googlemail.com
TP,
Could you give me, or point me to a link that demonstrates what you
mean by 'wrap' please.
Thanks for responding,
Lawrence
l***@googlemail.com
2007-07-30 14:26:23 UTC
Permalink
Post by TP
Hi Lawrence,
You need to add the Microsoft RDP Client Control to a
form--it is a COM Component. Then you can set its
properties, call its methods, and respond to its events.
For example, after you have the control on the form,
you could put a button with code to perform the
private void button1_Click(object sender, EventArgs e)
{
axMsRdpClient31.Server = "servername";
axMsRdpClient31.Connect();
}
You will also want to respond to the various events as
your needs dictate such as OnDisconnected.
Documentation of the methods, properties, and events are
up on MSDN.
-TP
Post by l***@googlemail.com
TP,
Could you give me, or point me to a link that demonstrates what you
mean by 'wrap' please.
Thanks for responding,
Lawrence- Hide quoted text -
- Show quoted text -
TP,

I appreciate your help with this. I don't have that as a COM object
and I've really tried searching MSDN for anything ro do with
RemoteDesktop but I must be doing something wrong - as I find
nothing. Could you tell me the name of the Class? I tried
RemoteDesktop and RdpClient31 but it doesn't get me anywhere...

Thanks again,

Lawrence
TP
2007-07-30 14:47:47 UTC
Permalink
In your list of COM Components, scroll down and look
for the following (entries will vary depending on which
TS client(s) you have installed):

Microsoft RDP Client Control
Microsoft RDP Client Control (redist)
Microsoft Terminal Services Control

The files to look for are mstscax.dll and msrdp.ocx

IMsRdpClient

http://msdn2.microsoft.com/en-us/library/Aa381344.aspx

-TP
Post by l***@googlemail.com
TP,
I appreciate your help with this. I don't have that as a COM object
and I've really tried searching MSDN for anything ro do with
RemoteDesktop but I must be doing something wrong - as I find
nothing. Could you tell me the name of the Class? I tried
RemoteDesktop and RdpClient31 but it doesn't get me anywhere...
Thanks again,
Lawrence
l***@googlemail.com
2007-07-30 15:16:38 UTC
Permalink
Post by TP
In your list of COM Components, scroll down and look
for the following (entries will vary depending on which
Microsoft RDP Client Control
Microsoft RDP Client Control (redist)
Microsoft Terminal Services Control
The files to look for are mstscax.dll and msrdp.ocx
IMsRdpClient
http://msdn2.microsoft.com/en-us/library/Aa381344.aspx
-TP
Post by l***@googlemail.com
TP,
I appreciate your help with this. I don't have that as a COM object
and I've really tried searching MSDN for anything ro do with
RemoteDesktop but I must be doing something wrong - as I find
nothing. Could you tell me the name of the Class? I tried
RemoteDesktop and RdpClient31 but it doesn't get me anywhere...
Thanks again,
Lawrence- Hide quoted text -
- Show quoted text -
TP,

Thanks.

I found Microsoft Terminal Services Control refernce
and put in a Using MSTSClib line.

Is there a different between a MsRdpClient and an IMsRdpClient?

What I want is to programmatically open RemoteDesktop (as if it had
been done via GUI) so that users can view it, but be able to monitor
in c# to see if it gets disconnected. Do you think that it possible?

Lawrence
TP
2007-07-30 15:33:28 UTC
Permalink
Lawrence,

Yes, it is possible. The sample code I gave you is the
minimum to establish a connection and interact with
a session on the server.

Now write code to respond to the events you are
interested in as well as add features to the form such as
the ability to specify server name, display options,
redirection options, etc.

In a couple of hours or so you should be able to
have a custom version that has all the features of the
regular Remote Desktop Client plus the ability to monitor
and respond to disconnects.

-TP
Post by l***@googlemail.com
TP,
Thanks.
I found Microsoft Terminal Services Control refernce
and put in a Using MSTSClib line.
Is there a different between a MsRdpClient and an IMsRdpClient?
What I want is to programmatically open RemoteDesktop (as if it had
been done via GUI) so that users can view it, but be able to monitor
in c# to see if it gets disconnected. Do you think that it possible?
Lawrence
l***@googlemail.com
2007-07-30 15:40:32 UTC
Permalink
Post by TP
Lawrence,
Yes, it is possible. The sample code I gave you is the
minimum to establish a connection and interact with
a session on the server.
Now write code to respond to the events you are
interested in as well as add features to the form such as
the ability to specify server name, display options,
redirection options, etc.
In a couple of hours or so you should be able to
have a custom version that has all the features of the
regular Remote Desktop Client plus the ability to monitor
and respond to disconnects.
-TP
Post by l***@googlemail.com
TP,
Thanks.
I found Microsoft Terminal Services Control refernce
and put in a Using MSTSClib line.
Is there a different between a MsRdpClient and an IMsRdpClient?
What I want is to programmatically open RemoteDesktop (as if it had
been done via GUI) so that users can view it, but be able to monitor
in c# to see if it gets disconnected. Do you think that it possible?
Lawrence- Hide quoted text -
- Show quoted text -
TP,

You have been a great help!

I am able to run following code without errors, but, no RDP window
appears. I looked for a .visable property, but there does not seem to
be one. Is there something I am missing? Sorry, to ask again, but you
have been very accommodating...

Lawrence

IMsRdpClient RDP = new MsRdpClient();
RDP.Server = "156.4x.xx.xx";
RDP.UserName = "xxxx";
RDP.FullScreen = true;
RDP.DesktopHeight = 300;
RDP.DesktopWidth = 300;
RDP.Connect();
l***@googlemail.com
2007-07-30 16:19:39 UTC
Permalink
Post by l***@googlemail.com
Post by TP
Lawrence,
Yes, it is possible. The sample code I gave you is the
minimum to establish a connection and interact with
a session on the server.
Now write code to respond to the events you are
interested in as well as add features to the form such as
the ability to specify server name, display options,
redirection options, etc.
In a couple of hours or so you should be able to
have a custom version that has all the features of the
regular Remote Desktop Client plus the ability to monitor
and respond to disconnects.
-TP
Post by l***@googlemail.com
TP,
Thanks.
I found Microsoft Terminal Services Control refernce
and put in a Using MSTSClib line.
Is there a different between a MsRdpClient and an IMsRdpClient?
What I want is to programmatically open RemoteDesktop (as if it had
been done via GUI) so that users can view it, but be able to monitor
in c# to see if it gets disconnected. Do you think that it possible?
Lawrence- Hide quoted text -
- Show quoted text -
TP,
You have been a great help!
I am able to run following code without errors, but, no RDP window
appears. I looked for a .visable property, but there does not seem to
be one. Is there something I am missing? Sorry, to ask again, but you
have been very accommodating...
Lawrence
IMsRdpClient RDP = new MsRdpClient();
RDP.Server = "156.4x.xx.xx";
RDP.UserName = "xxxx";
RDP.FullScreen = true;
RDP.DesktopHeight = 300;
RDP.DesktopWidth = 300;
RDP.Connect();- Hide quoted text -
- Show quoted text -
I assume I should see the normal RDP window when I call connect? or is
that not the case?

Lawrence
TP
2007-07-30 18:26:09 UTC
Permalink
Lawrence,

Here are some steps to get you started:

1. Start a new c# windows project
2. Tools-->Choose Toolbox Items-->COM components tab,
check Microsoft RDP Client Control (or similar), click OK
3. Drag the RDP control from the toolbox and drop it on your form
4. Drag a button from the toolbox and drop it on your form
5. Type the code for the button's click event, use my sample
code from earlier as a guideline, making changes/additions
where necessary

Once you get the above working fine you can start adding
features to suit your tastes--perhaps you want one form for
all of the connection settings and a separate form to hold the RDP
control.

-TP
Post by l***@googlemail.com
TP,
You have been a great help!
I am able to run following code without errors, but, no RDP window
appears. I looked for a .visable property, but there does not seem to
be one. Is there something I am missing? Sorry, to ask again, but you
have been very accommodating...
Lawrence
IMsRdpClient RDP = new MsRdpClient();
RDP.Server = "156.4x.xx.xx";
RDP.UserName = "xxxx";
RDP.FullScreen = true;
RDP.DesktopHeight = 300;
RDP.DesktopWidth = 300;
RDP.Connect();
l***@googlemail.com
2007-07-31 08:23:24 UTC
Permalink
Post by TP
Lawrence,
1. Start a new c# windows project
2. Tools-->Choose Toolbox Items-->COM components tab,
check Microsoft RDP Client Control (or similar), click OK
3. Drag the RDP control from the toolbox and drop it on your form
4. Drag a button from the toolbox and drop it on your form
5. Type the code for the button's click event, use my sample
code from earlier as a guideline, making changes/additions
where necessary
Once you get the above working fine you can start adding
features to suit your tastes--perhaps you want one form for
all of the connection settings and a separate form to hold the RDP
control.
-TP
Post by l***@googlemail.com
TP,
You have been a great help!
I am able to run following code without errors, but, no RDP window
appears. I looked for a .visable property, but there does not seem to
be one. Is there something I am missing? Sorry, to ask again, but you
have been very accommodating...
Lawrence
IMsRdpClient RDP = new MsRdpClient();
RDP.Server = "156.4x.xx.xx";
RDP.UserName = "xxxx";
RDP.FullScreen = true;
RDP.DesktopHeight = 300;
RDP.DesktopWidth = 300;
RDP.Connect();- Hide quoted text -
- Show quoted text -
TP,

Great - got that working.

Could you tell me how to put an ondisconnected handler in?

Do I create a method with that name?

I find there is no sample code on MSDN at all - otherwise I would not
continue to bother you.

Many thanks,

Lawrence
l***@googlemail.com
2007-07-31 08:56:20 UTC
Permalink
Post by l***@googlemail.com
Post by TP
Lawrence,
1. Start a new c# windows project
2. Tools-->Choose Toolbox Items-->COM components tab,
check Microsoft RDP Client Control (or similar), click OK
3. Drag the RDP control from the toolbox and drop it on your form
4. Drag a button from the toolbox and drop it on your form
5. Type the code for the button's click event, use my sample
code from earlier as a guideline, making changes/additions
where necessary
Once you get the above working fine you can start adding
features to suit your tastes--perhaps you want one form for
all of the connection settings and a separate form to hold the RDP
control.
-TP
Post by l***@googlemail.com
TP,
You have been a great help!
I am able to run following code without errors, but, no RDP window
appears. I looked for a .visable property, but there does not seem to
be one. Is there something I am missing? Sorry, to ask again, but you
have been very accommodating...
Lawrence
IMsRdpClient RDP = new MsRdpClient();
RDP.Server = "156.4x.xx.xx";
RDP.UserName = "xxxx";
RDP.FullScreen = true;
RDP.DesktopHeight = 300;
RDP.DesktopWidth = 300;
RDP.Connect();- Hide quoted text -
- Show quoted text -
TP,
Great - got that working.
Could you tell me how to put an ondisconnected handler in?
Do I create a method with that name?
I find there is no sample code on MSDN at all - otherwise I would not
continue to bother you.
Many thanks,
Lawrence- Hide quoted text -
- Show quoted text -
Actually found some code at last!

Thanks TP got that all working now.

But I have another question please: How can I connect as 'console'
please. i.e. when I am connecting to Srver where more than one session
can be established?

normally I run 'mstsc /console' is there a way I could specify that?

Lawrence
l***@googlemail.com
2007-07-31 12:24:11 UTC
Permalink
Post by l***@googlemail.com
Post by l***@googlemail.com
Post by TP
Lawrence,
1. Start a new c# windows project
2. Tools-->Choose Toolbox Items-->COM components tab,
check Microsoft RDP Client Control (or similar), click OK
3. Drag the RDP control from the toolbox and drop it on your form
4. Drag a button from the toolbox and drop it on your form
5. Type the code for the button's click event, use my sample
code from earlier as a guideline, making changes/additions
where necessary
Once you get the above working fine you can start adding
features to suit your tastes--perhaps you want one form for
all of the connection settings and a separate form to hold the RDP
control.
-TP
Post by l***@googlemail.com
TP,
You have been a great help!
I am able to run following code without errors, but, no RDP window
appears. I looked for a .visable property, but there does not seem to
be one. Is there something I am missing? Sorry, to ask again, but you
have been very accommodating...
Lawrence
IMsRdpClient RDP = new MsRdpClient();
RDP.Server = "156.4x.xx.xx";
RDP.UserName = "xxxx";
RDP.FullScreen = true;
RDP.DesktopHeight = 300;
RDP.DesktopWidth = 300;
RDP.Connect();- Hide quoted text -
- Show quoted text -
TP,
Great - got that working.
Could you tell me how to put an ondisconnected handler in?
Do I create a method with that name?
I find there is no sample code on MSDN at all - otherwise I would not
continue to bother you.
Many thanks,
Lawrence- Hide quoted text -
- Show quoted text -
Actually found some code at last!
Thanks TP got that all working now.
But I have another question please: How can I connect as 'console'
please. i.e. when I am connecting to Srver where more than one session
can be established?
normally I run 'mstsc /console' is there a way I could specify that?
Lawrence- Hide quoted text -
- Show quoted text -
TP,

I worked that out too. Making some progress here!

I have an issue I can't resolve - when I connect I go to fullscreen
mode then if I minmize window it collapses to taskbar, but I can't
maximise it again - all options are greyed out except 'close'...

Lawrence
ThomasT.
2008-06-06 17:15:35 UTC
Permalink
Hi,

I think you have to use a tool to import the ocx that will generate
AxMSTSCLib.dll for you, then

you can use the OCX in .NET project. I suggest you to download Royal TS and
learn from it,

it's an open source program that wraps the MSRDP.OCX, very nice. Search on
internet you will find some more

Regards

ThomasT.
TP (or anyone),
I am wading through COM for the first time. One of my first tasks is to
get a Windows service (a C# project in VS 2008) instantiate an
IMsRdpClient object and make a TS connection.
I found this post that was helpful, however when going through the list of
1. Start a new c# windows project
2. Tools-->Choose Toolbox Items-->COM components tab,
check Microsoft RDP Client Control (or similar), click OK
3. Drag the RDP control from the toolbox and drop it on your form
4. Drag a button from the toolbox and drop it on your form
5. Type the code for the button's click event, use my sample
code from earlier as a guideline, making changes/additions
where necessary
I became stuck on number 3. On a Windows Form App project (I did this in
parallel), the "Microsoft RDP Client Control" does appear under "All
Windows Forms" in the toolbox. However, it does not appear in the Windows
service project.
Any explanation of why would be appreciated. Any solutions, even more so!
Thanks to all for reading
KK
Loading...