By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,493 Members | 3,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,493 IT Pros & Developers. It's quick & easy.

Remote Desktop Connection from c#

P: n/a
Hi,

Is there a way to launch an remote desktop connection to a specified
server/username from c#?

If there's a way to send the password too that would be useful, but i'm
not so interested in that if its a problem.

Thanks!
Andrew

Jul 28 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
you could probably run process.start against the mstsc.exe program (remote
connection manager) to shell an instance of Remote Conenction Manager to
create your connection using a .rdp file as your command line argument.
You'll need to dig about for the correct argument syntax but can start here:

http://technet2.microsoft.com/Window...e--RegardsJohn Timney (MVP)<tr******@hotmail.comwrote in messagenews:11**********************@i42g2000cwa.g ooglegroups.com...Hi,>Is there a way to launch an remote desktop connection to a specifiedserver/username from c#?>If there's a way to send the password too that would be useful, but i'mnot so interested in that if its a problem.>Thanks!>>Andrew>

Jul 28 '06 #2

P: n/a
John Timney (MVP) wrote:
you could probably run process.start against the mstsc.exe program (remote
connection manager) to shell an instance of Remote Conenction Manager to
create your connection using a .rdp file as your command line argument.

Cool, thanks alot thats exactly what I needed.
Having tried this however a problem has emerged;

When i run the application from a networked location i get a
SecurityException :(

What can i do about this?

Thanks!

Andrew

Below is the top of the stack trace
System.Security.SecurityException: Request failed.
at
System.Security.CodeAccessSecurityEngine.ThrowSecu rityException(Assembly
asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle
rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at
System.Security.CodeAccessSecurityEngine.ThrowSecu rityException(Object
assemblyOrString, PermissionSet granted, PermissionSet refused,
RuntimeMethodHandle rmh, SecurityAction action, Object demand,
IPermission permThatFailed)
at
System.Security.CodeAccessSecurityEngine.CheckSetH elper(PermissionSet
grants, PermissionSet refused, PermissionSet demands,
RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction
action, Boolean throwException)
at
System.Security.CodeAccessSecurityEngine.CheckSetH elper(CompressedStack
cs, PermissionSet grants, PermissionSet refused, PermissionSet demands,
RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
at Form1.menuItemClicked_RDC(Object sender, EventArgs e)

The action that failed was: LinkDemand
The type of the first permission that failed was:
System.Security.PermissionSet
The Zone of the assembly that failed was: Intranet

Jul 28 '06 #3

P: n/a
Code executed from remote locations is run (by default) at a different trust
level. You need to tell your PC(s) to trust the code enough to run the
Process.Start command; in 1.1 you can assign trust using caspol.exe, or the
..net configuration utility (start menu), and you can assign trust via e.g.
the network path, the SNK, etc... alternatively, in 2.0 you can use a
ClickOnce manifest signed with a code-signing cetificate that is in the
user's certificate trust chain - you can then assign the trust in the
deployment package.

Marc
Jul 28 '06 #4

P: n/a
If you like, there is RDP ActiveX control that you can use in C# project.
It has good functionality, lots of events, it supports virtual channels and
you can personalize it almost as you like.
There is not a lot of documentation but the component is quite self
documenting.
Some documentation is here:

http://msdn.microsoft.com/library/de...interfaces.asp

<tr******@hotmail.comha scritto nel messaggio
news:11**********************@i42g2000cwa.googlegr oups.com...
Hi,

Is there a way to launch an remote desktop connection to a specified
server/username from c#?

If there's a way to send the password too that would be useful, but i'm
not so interested in that if its a problem.

Thanks!
Andrew

Jul 28 '06 #5

P: n/a
(clarification; the 1.1 options also apply in 2.0 - but the ClickOnce route
is simpler as you don't need to make policy changes on each client)

Marc
Jul 28 '06 #6

P: n/a

Marc Gravell wrote:
Code executed from remote locations is run (by default) at a different trust
level. You need to tell your PC(s) to trust the code enough to run the
Process.Start command; in 1.1 you can assign trust using caspol.exe, or the
.net configuration utility (start menu), and you can assign trust via e.g.
the network path, the SNK, etc... alternatively, in 2.0 you can use a
ClickOnce manifest signed with a code-signing cetificate that is in the
user's certificate trust chain - you can then assign the trust in the
deployment package.

Marc

Cool, Thanks!

I've been reading up about this ClickOnce business but I'm a bit
confused by some of it.

Do I have to use an installer to setup all this trust business?

I just want to be able to distribute the app as an exe. Nice and simple
:)
Andrew

Jul 28 '06 #7

P: n/a
Do I have to use an installer...

Nope; with both online-only and installed ClickOnce deployments, your app
(when published) gets wrapped in a ".application" file; users execute the
".application", which deals with all the fun of "is it already installed?
does it need to be? is it the current version? do I trust it? has someone
tampered with the files?" questions... all the user sees (the first time) is
"wanna run this?" [paraphrased] (subsequent executes are silent). More
importantly, because it is system-managed, even a non-administrator on a
locke-down PC can install (if offline mode is enabled) the app into their
start menu. Handy.

In VS2005, look at the project properties, on the "Publish" and "Security"
tabs; the latter allows you to determine the trust settings, the former
allows you to generate the manifest (and supporting files); note that you
can publish directly to a UNC to support your network usage.

Marc
Jul 28 '06 #8

P: n/a
Hello All,

Let me know if there is any way that I connect to remote desktop from
command line or any other utility. I would need the command to log off
the session as wel..
Though mstsc.exe /v: is available i should hav manual intervention to
enter the credentials..

Also let me know how we can do it through any of c# classes.
Sample code will be of great help!!!

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.