Detect Server Display Resolution

余生长醉 提交于 2019-12-13 05:35:38

问题


On windows server 2008 can I have a web service or something I can query from a C# application as to the display properties (resolution (height & width)). The C# application does not run on the server so I cannot just detect it from the application itself.

Addition to help explain why:

I will have a user named "display" and that will be logged on displaying a website (on the server) and I want to be able to check the display from the desktop application so the user knows what resolution to design a template for. The resolution will change from different displays so it can't be a set value.


回答1:


I'd recommend just querying the server using WMI. Check the third example here:

http://msdn.microsoft.com/en-us/library/aa394591%28v=vs.85%29.aspx




回答2:


My Code

This is the code that I used to solve the problem:

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);
}


来源:https://stackoverflow.com/questions/5318836/detect-server-display-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!