Running an external application from within a workflow

  • 27 June 2016
  • 5 replies

Badge +5

To run an executable from within a workflow k2 for visual studios should be used, as we will need to execute custom code from within the workflow which can easily be done from K2 for Visual Studio.





Firstly, on the workflow we will need to add a server event.












Right click on the server event and select View Code and then Event Item.












After event item was selected a new tab will open in Visual Studio.



We can then add code to start an external application with parameters as shown in the following example












This snipped of code will execute the “Executable.exe” on the local server as specified by the location @”c:TempExecutable.exe” with a parameter in this case being a value received from the “K2.ProcessInstance.folio”






note that after the executable filename and path the “,” comma character allows you to add an argument.






This project can then be deployed and the Application specified in the custom code will be executed on this event in the workflow.



For executing external applications from within a workflow over a network, the following link may server as some guide lines on how this can be achieved.




5 replies

Badge +4

I have tried this and I cannot get the remote application to launch.

Basically what i am doing is trying to start powershell and running a powershell script but for some reason this will not launch it.  I have code around Process.Start that verifies that the code is running without error but i cannot figure out why the Process.Start is not kicking off.  It never errors out, it just does not launch the powershell portion.


Any ideas?



My code looks like this:


using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Diagnostics;
using System.Net.Mail;
using System.Management;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
using SourceCode.KO;
using SourceCode.Workflow.Common.Extenders;

using hostContext = Project.EventItemContext;
namespace ExtenderProject
public partial class EventItem : ICodeExtender<hostContext>
public void Main(Project.EventItemContext K2)
MailMessage mail = new MailMessage("", "");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "";

//Found alternate way of launching powershell, not working
PowerShell ps = PowerShell.Create();
ps.AddScript(@"C:Program FilesTIDALTESCmdLinein

//This is the suggested code and it does not launch
string strCmdText;
strCmdText = @"c:
System.Diagnostics.Process.Start(@"c:windowssystem32windowspowershellv1.0powershell.exe", strCmdText);

//This mail code launches successfully and i receive the email it sends.
mail.Subject = "Mail from K2 Server Event";
mail.Body = "This email is from the server event in the K2 runbook workflow. " +
catch(Exception e)
mail.Subject = "Mail from K2 Server Event";
mail.Body = e.Message;
Badge +5

Have you looked at these options instead of creating your own code:


Powershell projects on the K2 Market:


Badge +4

I was using the suggested method provided by K2 support, I didnt realize that the two projects you listed existed.


I tried the downloading the two options you suggested but something is wrong with the zip files on both, they cannot be extracted because they are seen as invalid by Windows.

Badge +4

I cannot get these to work, have you used them?  Do they not work on 4.6.9?

Danny are you able to find solution.After all approvals i need to run powershell script.Do you have any idea to launch powershell and execute script by passing values to script