开发者

Programmatically create and launch and RDP session (without gui)

开发者 https://www.devze.com 2022-12-28 22:19 出处:网络
I\'d like to know if there is a way to create and launch a Remote Desktop Session on a Windows Server programmatically.

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.


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

mstsc.exe documentation on MSDN


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号