Skip to main content
InSource Solutions

TN WW255 Using Windows PowerShell to Monitor and Control Wonderware Processes

Description

 

This article from InSource shows how to use a combination of scripts to monitor a Wonderware process to see if it's running, and then perform some action if it's not running.  The process uses Windows PowerShell and VBScripts.

  • Author: Rufus Handsome
  • Published: 10/30/2019
  • Applies to: Wonderware versions 2014R2 and 2017 all versions

Details

// *********Power Shell Script  "filename.ps1" to see if a process is running or not, then kill another  process  if not ******************** //

// ********* In the below example: ************************************************************** //

//  1.) Monitor WindowViewer (view.exe) to see if it's running,                         ************* //

//  2.) If it's not running, Stop-Process named "notepad" in this example        ************  //

//  3.) Else do something else like echo "Running"                                             ************ //

// ************************************* CODE FOLLOWS ************************************** //

if ((get-process "view" -ea SilentlyContinue) -eq $Null) { Stop-Process -processname "notepad"
}
 
else {
       echo "Running"
}
 
// ********* END CODE for Power Shell Script ************************* //
 
 
// *********  In the next VB Script example, we are simply using this script to call the PowerScript without popping up a DOS window. **************//
 
 
// ****** BEGIN Code "callpsprog.vbs" VBScript ************************ //
 
Set objShell = CreateObject("WScript.Shell")
objShell.Run "CMD" /C START /B " & objShell.ExpandEnvironmentStrings("%SystemRoot%") & "\System32\WindowsPowerShell\v1.0\powershell.exe  -file " & "c:\filename.ps1", 0, False
set objShell = Nothing
 
// ***************** END CODE  *************************** //