adun
adun

Reputation: 191

Programmatically create and launch and RDP session (without gui)

I'd like to know if there is a way to create and launch a Remote Desktop Session on a Windows Server programmatically.

I'm trying to make an automatic tool to create Local Users and then launch the associate RDP session. I've already made LocalUser creation and adding them to Remote Desktop Users (using net.exe). But I'm struck with the next step : create and launch user's rdp-session. I don't know how to handle this problem without having the Remote Desktop Client Gui.

I'm working on a Windows Server 2003 and I'm using VS2008 with .NET 3.5.

Regards.

Upvotes: 7

Views: 36583

Answers (3)

Josh Yeager
Josh Yeager

Reputation: 3793

You can call mstsc.exe and pass parameters on the command line to tell it what to connect to.

mstsc.exe documentation on MSDN

Upvotes: 17

adun
adun

Reputation: 191

First, I've found that an option on the server is needed to enable Terminal Service autologin.

  1. On the Terminal Server, click Start, point to Programs, point to Administrative Tools, and then click Terminal Server Connection Configuration.
  2. Double-click the rdp-tcp connection, and then click Advanced. If you want to modify properties for ICA clients, double-click the ica-rdp connection instead, and then click Properties.
  3. In the AutoLogon section, click to clear the Prompt for Password check box.
  4. Click OK, click OK, and then click Exit on the Connection menu.

source : support.microsoft.com/kb/260711

After that, I've made something based on this project : codeproject.com/KB/cs/RemoteDesktop_CSharpNET.aspx For what I've tested, I think it's not possible to omit an RDP Client connection (MsTscLib or mstsc.exe) I've got something working but it's certainly bad style. I'm using ActiveX Component Events to know the result of the connection. Ie : OnLogonError and OnLoginComplete.

here my source : http://codepaste.net/uiuuxc

I'm awaiting your comments.

Upvotes: 0

tyranid
tyranid

Reputation: 13318

You can use the Remote Desktop ActiveX control to connect, you would need to host it in a Form but the form wouldn't need to be visible. For an example see http://www.codeproject.com/KB/cs/RemoteDesktop_CSharpNET.aspx

Upvotes: 2

Related Questions