首页 > 解决方案 > 检测 Kofax 是否启动了自定义模块或用户

问题描述

当自定义模块启动时,我可以使用

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

在后台服务和 WinForms 应用程序之间切换。但我也可以在不启动 Kofax 的情况下运行 .exe 文件。

是否可以检查 Kofax 是否启动了该模块?我的示例代码看起来像

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

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

标签: kofax

解决方案


Kofax Capture 启动自定义模块的唯一上下文是用户尝试从 Batch Manager 处理批次,并且该批次当前在您的自定义模块的队列中。如果您指的是除此之外的其他内容,那么您需要澄清您的问题。

发生这种情况时,会使用附加参数调用为您的自定义模块注册的路径,其中最值得注意的是 -B###,其中 ### 是十进制批次 ID。有关这方面的更多详细信息,请参阅 Kofax 知识库文章1713,该文章较旧但仍适用于当前版本。

因此,您可以使用这样的函数来检查预期的参数。

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;
}

推荐阅读