2011-03-15 82 views
0

在windows server 2008上,我可以使用Web服務或我可以從C#應用程序查詢顯示屬性(分辨率(高度&寬度))的內容。 C#應用程序不在服務器上運行,所以我不能僅從應用程序本身檢測它。檢測服務器顯示分辨率

除了幫解釋:

我將有一個用戶名爲「顯示器」,並且將上顯示的網站(服務器)登錄,我希望能夠從桌面檢查顯示應用程序,以便用戶知道要爲其設計模板的分辨率。分辨率將從不同的顯示改變,因此它不能是一個設定值。

+1

爲什麼一個客戶端應用程序不運行服務器需要知道服務器的顯示分辨率(順便提一句,它可能只有命令行界面)? – Oded 2011-03-15 22:28:55

+0

您是否要求客戶端應用程序檢索服務器屏幕的顯示尺寸? – 2011-03-15 22:30:20

+0

你的意思是你服務器上顯卡的最大分辨率可以支持嗎?或者默認分辨率('HLM \ SYSTEM \ CurrentControlSet \ Control \ Video \ .... \ 0000 \ DefaultSettings')?或者爲特定的RDP用戶設置的分辨率? – 2011-03-15 22:59:44

回答

0

我的代碼

這是我用來解決該問題的代碼:

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