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

发布于 2024-12-05 12:22:45 字数 1505 浏览 0 评论 0原文

我想在安装 Windows 服务的 Win2k8R2 Server Web Edition 上远程启动程序。

据我所知,只有在存在“screen>0”的情况下才可能进行服务安装 - 这意味着用户必须登录才能执行此操作(我在某处读到登录对话框窗口代表“screen 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 没有被执行吗?我没有任何错误,只是没有启动。

或者有人知道远程安装服务的更好方法吗?

提前致谢!

I want to remotely start a program on a Win2k8R2 Server, Web Edition, which installs Windows services.

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).
So to get a screen, I open up a RDP connection and then trigger the setup exe which installs everything silently.

I made it run on Windows Server 2003 already. On 2008 R2 though it doesn't work anymore.
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? I don't have any error, it just doesn't start.

Or anyone knows a better method to remotely install services?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弄潮 2024-12-12 12:22:45

您不需要调用 Disconnect()。当使用 StartProgram 方法时,您使用的是过去所谓的“备用 Shell”方法。这意味着当程序终止时,会话将自动关闭/断开连接。

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

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

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

此外,我设置了以下参数:

// 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

You should not need to call Disconnect(). When using the StartProgram approach you are using what used to be called the 'Alternate Shell' approach. 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'.

I recently wrote an ActiveX library that initiates an Windows 2008 RDS session using the StartProgram parameter. Once the user closes the program that is started automatically when the RDS session starts, the RDS session automatically terminates. So you shouldn't need the looping mechanism nor the call to Disconnect() with your approach.

In my code, for user credentials, I specify the domain as well. Is your user account a Windows Domain account? 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文