Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Scroll ignore




Scroll ignore


Article status


kb-articleINLINE

Greenexternal 

Link to be provided outside of Bosch


kb-articleINLINE

Yellowinternal

Internal document. This article cannot be provided outside of Bosch.




Question

How to run external executable within BVMS SDK scriplet?

Answer

For more details about how to execute scriplets in the BVMS SDK, please check:

Call .bat files scriplet:

 

Example for BVMS scriplet    

    [Scriptlet("dbb99725-39ee-4bcf-972c-2f270aea727d")]
    public void runExternalBatFile(EventData e)
    {        string fullBatPath = @"C:\temp\HelloWorld.bat";

        var process = new Process()
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = "cmd.exe",
                Arguments = "/C C:\\temp\\HelloWorld.bat",

                UseShellExecute = false,
                CreateNoWindow = false,
            }
        };
        process.Start();
    }

   

Example for a method to be used in BVMS SDK based C# application
   

public void runExternalBatFile()
    {

//this is an example path to the test bat file called HelloWorld.bat
        string fullBatPath = @"C:\scripts\cameras_OFF.bat";

        var process = new Process()
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = "cmd.exe",

//$ is a short-hand for String.Format, that is part of

//C# 6
                Arguments = $"/C \"{fullBatPath}\"",
                UseShellExecute = false,
                CreateNoWindow = false,
            }
        };
        process.Start();
    }
}

External processes can be started within server scriptlets. Check details on C#  System.Diagnostics, Process Class.


Limitation to keep in mind is that when they have some UI, this is never shown and there is no user interaction possible, because they are running under the 'Local System' account. The reason is that Windows services can't start applications with UI  and this is one Windows security design rule.

 
Further explanation for the above Limitation

The CentralServer which executes ServerScripts is running as Windows service under the 'Local System' account. Windows services are prohibited from interacting with a user or the desktop.
When a ServerScript starts further processes, they will be started, but they are child processes and they derive all properties from the parent process. That includes the user context, all security attributes and limitations as well. In this case, the new created child process is prohibited from interacting with a user or the desktop.



Scroll ignore


Add pictures, if necessaryadvancedINLINE


greenINLINE

MANDATORY --> after finishing this article, if you wrote advanced content in this section , you must to manually add the "advanced" label  This action is required to indicate that this article contains ADVANCED instructions for CTS/ SG or GK.

DO NOT CHANGE ANYTHING IN THIS SECTION!

advanced section

Please contact CTS / SG or GK team to view this section from draft space, if necessary


adINLINE

IMPORTANT! --> the content itself from here will be not displayed. The content from here will be displayed only when the "ad" label will be set after article creation. Only CTS/ SG or GK are allowed to use "ad" label.

PLEASE do not set "ad" label from beginning. Use it only when you need this info and REMOVE the "ad" label when finished!

Information below is for CTS, SG, GK reference and must be kept internal only.

If you are part of CTS, SG or GK team, please hide this section when you have finished using this article!

DO NOT CHANGE ANYTHING IN THIS SECTION!


This section will not be published externally and / or automatically downloaded in the PDF file!

Type your text/ advanced information here

Please write here the statement/answer/explanation


These are notes how to start external process that has UI within BVMS scriplet. This method requires programming effort.

  • creation of an UI application which opens an endpoint for inter-process-communication (IPC), e.g. a socket server.
  • The virtual input event starts execution of a server scriptlet, which connects to the IPC endpoint and sends some information (event name, state...).
  • The UI application receives the information and triggers the "certain action" which is mentioned above. This application could also run on a different machine - the server scriplet could establish a connection to an endpoint on an other machine.Here is an example server scriptlet which connects to a socket server.
    These information bases on following article:

https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/sockets/socket-services
  

public void SendDataBySocketClient(EventData e)

{
   this.Logger.Info("SendDataBySocketClient - Start script execution");
   try
   {
      // Example for getting the endpoint of the socket server: local host and port 11000 are used here.
      var strHostName = Dns.GetHostName();
      this.Logger.Info("SendDataBySocketClient - Local Machine's Host Name: " + strHostName);
      IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
      IPAddress ipAddress = ipEntry.AddressList[0];
      IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11000);
 
      Socket client = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
      client.Connect(ipEndPoint);
      while (true)
      {
         // Example for sending a message.
         var message = "EventType:" + e.Type + " DeviceName:" + e.DeviceName + " StateInfo:" + e.State.New + "<|EOM|>";
         var messageBytes = Encoding.UTF8.GetBytes(message);
         client.Send(messageBytes, SocketFlags.None);
 
         // Example for 'any kind of' handshake:
         var buffer = new byte[1024];
         var received = client.Receive(buffer, SocketFlags.None);
         var response = Encoding.UTF8.GetString(buffer, 0, received);
         if (response == "<|ACK|>")
         

{             this.Logger.Info("SendDataBySocketClient - Socket client received acknowledgment: " + response);             break;          }

      }
 
      client.Shutdown(SocketShutdown.Both);
   }
   catch (Exception ex)
   

{       this.Logger.Info("SendDataBySocketClient - Exception: " + ex.ToString());    }

 
   // this.Logger.Info("SendDataBySocketClient - Finish script execution");
}








Scroll only
scroll-pdftrue
scroll-officetrue
scroll-chmtrue
scroll-docbooktrue
scroll-eclipsehelptrue
scroll-epubtrue
scroll-htmltrue


You are using an Offline Version of these Article, please ensure to regularly check the corresponding online article on the Bosch Building Technologies Knowledge Base for any updates. Use the date and version information of the document as reference.

This is  created 

Check for Updateprimaryhttps://community.boschsecurity.com/t5/Bosch-Building-Technologies/ct-p/bt_community