2011-09-20 17 views
0

我想在安装Windows服务的Win2k8R2服务器Web版上远程启动一个程序。Windows Server 2008 R2远程服务安装:如何在C#之后的RDP连接之后执行程序?

服务安装只有在“屏幕> 0”时才有可能 - 这意味着用户必须登录才能这样做(我在某处读取登录对话框窗口代表“屏幕0”,如果我这里错了)。 因此,为了获得一个屏幕,我打开了一个RDP连接,然后触发安装exe文件,它安静地安装了一切。

我已经在Windows Server 2003上运行了它。在2008 R2上,尽管它不再工作。 我假设可能有一些安全策略,或甚至完全用其他技术来实现我想要的。

下面的代码:

this.axMsRdpClient7 = new AxMSTSCLib.AxMsRdpClient7(); 

// ... some GUI stuff happens here.. 

axMsRdpClient7.Server = hostname; 
axMsRdpClient7.UserName = username; 
axMsRdpClient7.AdvancedSettings.Compress = -1; 
axMsRdpClient7.AdvancedSettings2.DisplayConnectionBar = true; 
axMsRdpClient7.AdvancedSettings7.ClearTextPassword = userpassword; 
axMsRdpClient7.AdvancedSettings2.EncryptionEnabled = -1; 

// Set start program information. vvv THIS IS NOT GOING TO BE EXECUTED vvv 
axMsRdpClient7.SecuredSettings.StartProgram = executablePath + " " + arguments; 
axMsRdpClient7.SecuredSettings.WorkDir = workingDirectory; 

// ... here I'm attaching some events like OnDisconnect... 

// Start connection 
axMsRdpClient7.Connect(); 

// Now the startprogram should be executed, but doesn't. 
// (at this time its ok that I have to manually log off to reach disconnect. Except you have a better idea to disconnect after startprogram finishes) 
while (axMsRdpClient7.Connected != 0) 
{ 
    Application.DoEvents(); 
    Thread.Sleep(1); 
} 

// End connection 
axMsRdpClient7.Disconnect(); 

任何人都知道,为什么没有被执行StartProgram中?我没有任何错误,它只是不启动。

或者任何人都知道更好的方法来远程安装服务?

在此先感谢!

回答

1

您不应该调用Disconnect()。使用StartProgram方法时,您使用的是以前称为“Alternate Shell”的方法。这意味着程序终止时,会话将自动关闭/断开连接。

请参阅http://msdn.microsoft.com/en-us/library/ms861803.aspx,搜索'AlternateShell'。

我最近编写了一个使用StartProgram参数启动Windows 2008 RDS会话的ActiveX库。一旦用户关闭了RDS会话启动时自动启动的程序,RDS会话就会自动终止。所以你不应该需要循环机制,也不需要用你的方法调用Disconnect()。

在我的代码中,对于用户凭证,我也指定了域。您的用户是Windows域帐户吗?如果是这样,你可能也需要指定。

另外,I设置以下参数:

// server authentication is required - set Auth level to 2 
AdvancedSettings7.AuthenticationLevel := 2; 
// use CredSsp if the client supports it. 
AdvancedSettings7.EnableCredSspSupport := True; 
// setting PublicMode to false allows the saving of credentials, which prevents 
// prompting the user to log in 
AdvancedSettings7.PublicMode := False; 

HTH

相关问题