检测服务器显示分辨率
问题描述:
在windows server 2008上,我可以使用Web服务或我可以从C#应用程序查询显示属性(分辨率(高度&宽度))的内容。 C#应用程序不在服务器上运行,所以我不能仅从应用程序本身检测它。检测服务器显示分辨率
除了帮解释:
我将有一个用户名为“显示器”,并且将上显示的网站(服务器)登录,我希望能够从桌面检查显示应用程序,以便用户知道要为其设计模板的分辨率。分辨率将从不同的显示改变,因此它不能是一个设定值。
答
我建议只使用WMI查询服务器。这里检查第三个例子:
http://msdn.microsoft.com/en-us/library/aa394591%28v=vs.85%29.aspx
+0
非常感谢,我终于开始尝试这个,它运作良好!我已经接受了你的答案,因为这确实是最好的答案,我还添加了我的代码片段来协助其他人。 – *er 2011-03-24 01:25:45
答
我的代码
这是我用来解决该问题的代码:
System.Management.ConnectionOptions oConnectionOptions = new System.Management.ConnectionOptions();
{
oConnectionOptions.Username = ServerManagement.GetServerUser();
oConnectionOptions.Password = ServerManagement.GetServerPassword();
}
ManagementPath oPath = new ManagementPath("\\\\" + ServerManagement.GetServerAddress() + "\\root\\cimv2");
ManagementScope oScope = new ManagementScope(oPath, oConnectionOptions);
try
{
oScope.Connect();
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DesktopMonitor");
ManagementObjectCollection obj = searcher.Get();
foreach (ManagementObject service in obj)
{
this.DisplayHeight = Convert.ToInt16(service["ScreenHeight"]);
this.DisplayWidth = Convert.ToInt16(service["ScreenWidth"]);
}
}
catch (Exception)
{
MessageBox.Show("Cannot connect to server, please try again later.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
为什么一个客户端应用程序不运行服务器需要知道服务器的显示分辨率(顺便提一句,它可能只有命令行界面)? – Oded 2011-03-15 22:28:55
您是否要求客户端应用程序检索服务器屏幕的显示尺寸? – 2011-03-15 22:30:20
你的意思是你服务器上显卡的最大分辨率可以支持吗?或者默认分辨率('HLM \ SYSTEM \ CurrentControlSet \ Control \ Video \ .... \ 0000 \ DefaultSettings')?或者为特定的RDP用户设置的分辨率? – 2011-03-15 22:59:44