在windows server 2008上,我可以使用Web服務或我可以從C#應用程序查詢顯示屬性(分辨率(高度&寬度))的內容。 C#應用程序不在服務器上運行,所以我不能僅從應用程序本身檢測它。檢測服務器顯示分辨率
除了幫解釋:
我將有一個用戶名爲「顯示器」,並且將上顯示的網站(服務器)登錄,我希望能夠從桌面檢查顯示應用程序,以便用戶知道要爲其設計模板的分辨率。分辨率將從不同的顯示改變,因此它不能是一個設定值。
在windows server 2008上,我可以使用Web服務或我可以從C#應用程序查詢顯示屬性(分辨率(高度&寬度))的內容。 C#應用程序不在服務器上運行,所以我不能僅從應用程序本身檢測它。檢測服務器顯示分辨率
除了幫解釋:
我將有一個用戶名爲「顯示器」,並且將上顯示的網站(服務器)登錄,我希望能夠從桌面檢查顯示應用程序,以便用戶知道要爲其設計模板的分辨率。分辨率將從不同的顯示改變,因此它不能是一個設定值。
我建議只使用WMI查詢服務器。這裏檢查第三個例子:
http://msdn.microsoft.com/en-us/library/aa394591%28v=vs.85%29.aspx
非常感謝,我終於開始嘗試這個,它運作良好!我已經接受了你的答案,因爲這確實是最好的答案,我還添加了我的代碼片段來協助其他人。 – Prisoner 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