22146

Detect Server Display Resolution

Question:

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.

Answer1:

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

<a href="http://msdn.microsoft.com/en-us/library/aa394591%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa394591%28v=vs.85%29.aspx</a>

Answer2:

<strong>My Code</strong>

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

Recommend

  • Detect Removable Media Ejection Request in Windows Service
  • How to get OS version and Device Name of an Android device connected via USB with C#.net (VS2010/4.0
  • c#.NET USB device persistent identifier
  • Memory usage and time for execution for another process using C#?
  • Dealing with XElement null value
  • Creating an Order Column for encrypted data
  • How to best manage SMTP clients
  • Swift iOS don't recognize GCM library imports?
  • How to call a procedure using NHibernate that returns result from multiple tables?
  • Microsoft Excel Pivot miscalculation in Sum for positive and negative numbers
  • CSS - Cannot get one spanned style to override another inherited style and align left
  • Sensibility of combined Maven/Ant+Ivy build management for dual platform Desktop/Android deployment?
  • Suppressing passwd when calling sqlplus from shell script
  • Can I programmatically choose the Android layout folder?
  • Django invalid literal for int() with base 10
  • MS Access - How to change the linked table path by amend the table
  • MySQL Order by column = x, column asc?
  • xtable package: Skipping some rows in the output
  • Declaring variable dynamically in VB.net
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • C++ Partial template specialization - design simplification
  • Recording logins for password protected directories
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • Splitting given String into two variables - php
  • Why is the size of this struct 32?
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Controls, properties, events and timers running in design time
  • Window Size for Mac application
  • Check if a string to interpolate provides expected placeholders
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • WOWZA + RTMP + HTML5 Playback?
  • Calling of Constructors in a Java
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory
  • Observable and ngFor in Angular 2