Link to be provided outside of Bosch
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:
// ScriptType: ServerScript
// ScriptLanguage: CS
using System;
using System.Diagnostics;
using System.Collections.Generic;
using log4net;
using Bosch.Vms.Core;
using Bosch.Vms.SDK;
using System.Net;
[BvmsScriptClass()]
public class ServerScript : IDisposable
{
private readonly IServerApi Api;
private readonly ILog Logger;
public ServerScript(IServerApi api)
{
this.Logger = LogManager.GetLogger("ServerScript");
this.Api = api;
}
public void Dispose()
{
// Use this method to cleanup any resources here (consider fully implementing the Dispose pattern).
// For example, stop and dispose any started timers. Ensure that all threads that were started are stopped here.
// DO NOT BLOCK in this method for a very long time, as this may block the applications current activity.
}
public void CamerasON(EventData e)
{
string fullBatPath = @"C:\scripts\cameras_ON.bat";
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C \"{fullBatPath}\"",
UseShellExecute = false,
CreateNoWindow = false,
}
};
process.Start();
}
[Scriptlet("c8d87b59-846f-4d35-bdfe-e96707a00256")]
public void CamerasOFF(EventData e)
{
string fullBatPath = @"C:\scripts\cameras_OFF.bat";
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/C \"{fullBatPath}\"",
UseShellExecute = false,
CreateNoWindow = false,
}
};
process.Start();
}
}
Please contact CTS / SG or GK team to view this section from draft space, if necessaryadINLINE
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!
External processes can be started within server scriptlets. Check details on C# System.Diagnostics, Process Class.
System.Diagnostics.Process.Start("C:
temp
executable.exe");
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 only | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||
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 |