Skip to main content

Screen Grabs and Office Displays – Part 1

The challenge

There are countless tools for producing in-depth analytics and dashboards from complex enterprise systems. Many of these dashboards are presented through a web browser (such as vRealise Operations). These dashboards are critical for command centre operations but also often make good “office displays” showing the activity of a system.

The challenge, how do you share a display when it isn’t just a single web page? For example, the dashboard comprises of multiple windows from different applications all manually placed on a screen?

The solution

First thoughts were to use VNC to stream the desktop, however, this requires a direct network connection between the host and all the clients as well as additional software to be installed (e.g. TightVNC/RealVNC etc.).

In our case the data refresh was actually quite slow. There was no need for a video stream, indeed, a simple screen update every 30 seconds met our needs. The following PowerShell script runs on the same machine that is generating the dashboard. The script takes a screen shot/print screen and saves it to a network folder. Every 30 seconds this image is updated with a fresh screen shot.

Before the script can run you will probably need to have administrative permissions on the Windows desktop/server, however, you shouldn’t need to install any additional software components. Finally, don’t forget to set the execution policy (Set-ExecutionPolicy) in PowerShell if you get warnings about unsigned scripts not being trusted.

Once you have your image being updated on the network folder, a simple HTML webpage can display this image. The only network requirements are for the host machine to have write permission to the folder (to update the image) and the clients have read only (or better) access to the folder.

 

;  
#############################################################################
# Capturing a screenshot from a local machine and saving it to a folder
#
# *** DONT FORGET - need to set -> Set-ExecutionPolicy Unsigned ***
#
#############################################################################
 
# Location for save path
$File = "<path to shared folder on network>/screenprint.png"
 
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
 
# Gather Screen resolution information - note multiple screens if dual (or more) setup...
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = $Screen.Width
$Height = $Screen.Height
$Left = $Screen.Left
$Top = $Screen.Top
 
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
 
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
 
# Loop to take multiple screen captures
while($true){
   # Capture screen
   $graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
 
   # Save to file
   $bitmap.Save($File)
 
   Write-Output "Screenshot saved to:"
   Write-Output $File
 
   # Sleep for 30 seconds
   Start-Sleep -s 30
}

 

 

Leave a Reply