简体   繁体   English

Windows Server 2008 R2远程服务安装:在C#中进行RDP连接后如何执行程序?

[英]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.

相关问题 服务未响应使用Windows Server 2008 R2上的服务控制器的C#程序 - Service not responding to the c# program that uses service controller on windows server 2008 r2 如何使用Windows Service(C#)中的多线程在SQL Server 2008 R2中插入和更新同一插入的多条记录? - How to insert & update the same inserted multiple record in SQL Server 2008 R2 using multithread in windows service(C#)? 用c#.NET 4 vs2010编写的Windows服务不会安装在Server 2008 R2 Enterprise上 - windows service written in c# .NET 4 vs2010 will not install on Server 2008 R2 Enterprise Windows Server 2008 R2中的ODBC连接 - ODBC connection in Windows Server 2008 R2 Windows Server 2008 R2上的连接超时= 0 - Connection Timeout=0 on Windows Server 2008 R2 如何在C#中将图像从SQL Server 2008 R2检索到Datagridview [Windows应用程序] - How to retrieve image from SQL Server 2008 R2 to Datagridview in C# [Windows Application] Windows Server 2008 R2上的远程用户日志记录信息 - Remote User Logging Information on windows server 2008 r2 C#编码转换为UTF-8-Windows 7与Windows Server 2008 R2的行为不同? - C# encoding conversion to UTF-8 - different behavior on Windows 7 vs. Windows Server 2008 R2? 从C#程序创建新的SQL Server 2008 R2登录名 - Create new SQL Server 2008 R2 login from C# program 无法使用C#Web项目连接到SQL Server 2008 r2,错误:连接字符串无效 - Unable to connect to SQL Server 2008 r2 with C# web project, Error: Connection string not valid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM