检测服务器显示分辨率

发布于 2024-10-22 00:57:50 字数 248 浏览 4 评论 0原文

在 Windows Server 2008 上,我可以有一个 Web 服务或一些可以从 C# 应用程序查询显示属性(分辨率(高度和宽度))的东西。 C# 应用程序不在服务器上运行,因此我无法仅从应用程序本身检测它。

另外帮助解释原因:

我将有一个名为“display”的用户,该用户将登录并显示一个网站(在服务器上),并且我希望能够从桌面应用程序检查显示,以便用户知道要使用什么分辨率设计一个模板。分辨率会根据不同的显示器而变化,因此它不能是固定值。

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.

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

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

发布评论

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

评论(2

饮湿 2024-10-29 00:57:51

我建议只使用 WMI 查询服务器。在此处检查第三个示例:

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

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

千秋岁 2024-10-29 00:57:51

我的代码

这是我用来解决问题的代码:

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

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