7 Replies Latest reply on May 9, 2017 3:07 PM by mvenchiarutti

    Start Script



      Is it possible to run bat files on change of  values of a digital tag by using PI AF ? or other tools?


      Someone has an idea?


      Thanks by advance

        • Re: Start Script

          What is it that you are trying to acomplish in the end by running BAT files?

          Would PI Notification not help you in this case? Please provide any contexts and/or usecase to your query as it will be helpful to suggest you a path.




            • Re: Start Script



              I want to run PI SRVSTOP when power failure occured and UPS supply provides . I receive relevant information when power supply (digital status).

                • Re: Start Script

                  I see. Do you have any issues with PI Data Archive server while you experience power failure, such as corrupt archives etc?

                  If so, what is your version of data server? We increased resiliency of such curruption dramatically in PI 2012+.

                  Perhaps upgrading the server is a better way forward.


                  As Gavin suggested, we do not have out-of-the-box solution to this issue to launch other programs from a tag value. Are you familiar with powershell?

                  If then, powershell scripts can be written to

                  1. read value from PI continually
                  2. Check the value every 3 seconds to see if there is any failure
                  3. Start the script.


                  A pseudo scripts may be similar to below:

                  $targetPI = "YourPI"
                  $con = Connect-PIDataArchive -PIDataArchiveMachineName $targetPI
                  $tagmask = "YourTag"
                      $mytag = Get-PIPoint -Connection $con -Name $tagmask
                      $time = [System.DateTime]::Now
                          $val = Get-PIValue -Connection $con -PointName $tagmask -Time $time
                          $Timestamp = $val.TimeStamp
                          $value = $val.Value
                          if($value.Equals("False")) {
                              Write-Host $Timestamp :: $value
                          Else {
                              Start "C:\Program Files\PI\adm\pisrvstop.bat"
                          Start-Sleep -Seconds 3
                  Else {
                  Write-Host "Not Connected"
              • Re: Start Script

                You would most likely need to write a custom app or script to do this. There is no out-of-the-box functionality in PI software to launch other programs or open a shell.


                By the way, if there is a power failure and the UPS supplies a status to shutdown, it probably would be better to actually shutdown the machine (Windows), rather than just running pisrvstop.

                  • Re: Start Script

                    Hello Manuel,


                    I concur with Gavin. At a power outage, when running on UPS, you probably want to shut down Windows to avoid a hard shutdown when batteries become empty. What comes handy in that regards and what I am used to do with all my PI Data Archive installations, is to refer pisrvstop.bat as shutdown script.


                    - Start Windows Local Group Policy Editor (gpedit.msc)

                    - In the left pane, go to Computer Configuration -> Windows Settings -> Scripts (Startup/Shutdown)

                    - Double-click Shutdown (right pane)

                    - Add a new entry pointing to pisrvstop.bat


                    • Re: Start Script

                      Hi Gavin,


                      I don't know if ups manages correctyl the shutdown of servers so what I 'm searching alternative ways


                      Thank you for your reply


                      Best Regards,