[英]Windows Server 2008 R2 remote service installation: How to execute program after RDP Connection in C#?
I want to remotely start a program on a Win2k8R2 Server, Web Edition, which installs Windows services. 我想在Win2k8R2服务器Web版的远程启动程序,该服务器安装Windows服务。
Service installation is afaik only possible if there's a "screen>0" - that means a user must be logged in to do that (I read somewhere that the login dialog window is representing "screen 0", correct me if I'm wrong here). 只有在“ screen> 0”的情况下才可以安装服务,这意味着用户必须登录才能执行此操作(我在某处看到登录对话框窗口代表“ screen 0”,如果我错了,请更正我)。 So to get a screen, I open up a RDP connection and then trigger the setup exe which installs everything silently.
因此,要获得一个屏幕,我打开一个RDP连接,然后触发安装程序exe,该程序以无提示方式安装所有内容。
I made it run on Windows Server 2003 already. 我已经使其在Windows Server 2003上运行。 On 2008 R2 though it doesn't work anymore.
在2008 R2上,它不再起作用了。 I assume there may be some security policy or even completely other technique to achieve what I want.
我认为可能有一些安全策略甚至完全是其他技术来实现我想要的。
Here's the code: 这是代码:
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();
Anyone knows why StartProgram is not being executed? 有人知道为什么不执行StartProgram吗? I don't have any error, it just doesn't start.
我没有任何错误,只是没有开始。
Or anyone knows a better method to remotely install services? 还是有人知道更好的远程安装服务的方法?
Thanks in advance! 提前致谢!
You should not need to call Disconnect(). 您不需要调用Disconnect()。 When using the StartProgram approach you are using what used to be called the 'Alternate Shell' approach.
使用StartProgram方法时,将使用以前称为“备用Shell”方法的方法。 This means that when the program terminates, the session is automatically closed/disconnected.
这意味着当程序终止时,会话将自动关闭/断开连接。
See http://msdn.microsoft.com/en-us/library/ms861803.aspx , search for 'AlternateShell'. 请参阅http://msdn.microsoft.com/en-us/library/ms861803.aspx ,搜索“ AlternateShell”。
I recently wrote an ActiveX library that initiates an Windows 2008 RDS session using the StartProgram parameter. 我最近编写了一个ActiveX库,该库使用StartProgram参数启动Windows 2008 RDS会话。 Once the user closes the program that is started automatically when the RDS session starts, the RDS session automatically terminates.
一旦用户关闭了RDS会话启动时自动启动的程序,RDS会话就会自动终止。 So you shouldn't need the looping mechanism nor the call to Disconnect() with your approach.
因此,您不需要使用循环机制,也不需要使用Disconnect()进行调用。
In my code, for user credentials, I specify the domain as well. 在我的代码中,还为用户凭据指定了域。 Is your user account a Windows Domain account?
您的用户帐户是Windows域帐户吗? If so you probably need to specify that as well.
如果是这样,您可能还需要指定它。
Additionally, I set the following parameters: 此外,我设置了以下参数:
// 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 高温超导
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.