Search code examples
kofax

detect if Kofax launched custom module or User


When the custom module gets launched I can use

if (Environment.UserInteractive)
{
   // Run as WinForms app
}
else
{
   // Run as service
}

to switch between a background service and a WinForms app. But I can also run the .exe file without launching Kofax.

Is it possible to check if Kofax launched the module? My example code would look like

if (Environment.UserInteractive)
{
   // Run as WinForms app

   if (Application.LaunchedByKofax)
   {
      // Do something additional
   }
}
else
{
   // Run as service
}

Solution

  • The only context in which Kofax Capture launches your custom module is when a user tries to process a batch from Batch Manager, and that batch is currently in the queue for your custom module. If you are referring to something other than that, then you'll need to clarify your question.

    When that happens, the path registered for your custom module is called with additional parameters, the most notable of which is -B###, where ### is the decimal batch ID. For more details on this see Kofax KB article 1713, which is old but still applicable for current versions.

    Thus you can use a function like this to check for the expected parameters.

    public bool LaunchedFromBatchManager()
    {
        var args = Environment.GetCommandLineArgs();
    
        //args[0] will contain the path to your exe, subsquent items are the actual args
        if (args.Count() > 1)
        {
            // When a user tries to process a batch from batch manager, 
            // it launches the module with -B###, where ### is the decimal batch ID
            // see: http://knowledgebase.kofax.com/faqsearch/results.aspx?QAID=1713
            if (args[1].StartsWith("-B"))
            {
                return true;
            }
        }
    
        return false;
    }