0

我想远程启动一个 Win2k8R2 服务器,Web 版上的程序,它安装了 Windows 服务。

仅当存在“屏幕> 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 没有被执行?我没有任何错误,它只是没有启动。

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

提前致谢!

4

1 回答 1

1

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

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

我最近编写了一个使用 StartProgram 参数启动 Windows 2008 RDS 会话的 ActiveX 库。一旦用户关闭 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;

高温高压

于 2012-04-27T15:41:00.973 回答