0

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
}
Question3r
  • 2,166
  • 19
  • 100
  • 200

1 Answers1

2

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;
}
Stephen Klancher
  • 1,374
  • 15
  • 24
  • Just out of curiosity, couldn't the user just call the CM's exe directly? – Wolfgang Radl May 17 '19 at 17:38
  • Of course: the three scenarios are 1. Run as a service (!Environment.UserInteractive), 2. Launched by user directly (Environment.UserInteractive), 3 Launched by user by processing a batch from batch manager (Environment.UserInteractive && LaunchedFromBatchManager()). Does that answer the question, or am I overlooking something? – Stephen Klancher May 17 '19 at 18:18
  • 1
    Should have read that more thoroughly. OP already checks for `Environment.UserInteractive`. Thanks, Stephen! – Wolfgang Radl May 17 '19 at 18:22
  • No problem Wolfgang! – Stephen Klancher May 17 '19 at 18:26