开发者

Detect Server Display Resolution

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 k开发者_Python百科nows what resolution to design a template for. The resolution will change from different displays so it can't be a set value.


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜