在事件接收器中调用控制台应用程序(.exe)并获取错误

时间:2012-05-10 06:01:10

标签: sharepoint process ocr eventreceiver

我正在使用SharePoint基础。我有一个控制台应用程序,用于运行一些OCR进程。我从Windows服务调用控制台应用程序的exe,它工作正常。我试图从事件接收器调用相同的exe但无法调用exe并得到一些错误。事件接收器工作正常,但无法调用exe。我试图像notepad.exe一样调用其他exes,但得到同样的错误。详情如下:

代码:

public override void ItemAdded(SPItemEventProperties properties)
{

   try
   {
       base.ItemAdded(properties);
       Log("Event Occured.");
       string OCRedText = string.Empty;
       string Listname = properties.ListTitle;
       string itemName = Convert.ToString(properties.ListItem["Name"]);
       string itemTitle = Convert.ToString(properties.ListItem["Title"]);

       callService(); // Here is the method to call Process                

       SPListItem item = properties.ListItem;
       if (System.Threading.Monitor.TryEnter(myLock, TimeSpan.FromSeconds(100)))
       {
           if (Convert.ToString(item["OCRed"]) == "False")
           {                       
               item["OCRed"] = "True";
               Thread.Sleep(10000);
               item.SystemUpdate();
               Log("Item Added and Updated.");
           }
           else
           {
               Log("Can not update the Item.");
           }
       }
       Log("Event End."+"\r\n");
   }
   catch (Exception ex)
   {
       Log("Error in Item Added Event Receiver.");
       Log(ex.ToString());               
   }
}

public void callService()
{
    Log("Calling Service is not easy.");
    try
    {
        ProcessStartInfo pinfoService = new ProcessStartInfo();
        pinfoService.FileName = @"D:\Khan\khan.exe";
        //pinfoService.FileName = @"C:\Windows\System32\notepad.exe";
        pinfoService.UseShellExecute = false;
        pinfoService.RedirectStandardError = true;
        pinfoService.RedirectStandardInput = true;
        pinfoService.RedirectStandardOutput = true;
        pinfoService.CreateNoWindow = true;
        pinfoService.WindowStyle = ProcessWindowStyle.Hidden;
        Log("FileName: " + pinfoService.FileName);
        Log("Arguments for callService : "+pinfoService.Arguments);
        Process pService = new Process();

        pService.StartInfo = pinfoService;
        Log("Process Before Start.");
        Thread.Sleep(5000);
        pService.Start();
        Thread.Sleep(2000);
        Log("Process Before wait for exit.");
        pService.WaitForExit();
        Log("Process Completed.");
    }
    catch (Exception ex)
    {
        Log("Error in callService(). Please contact your Administrator.");
        Log(ex.ToString());
    }
}

以下是我遇到的错误pService.Start();

=========================================

Info : Process Before Start.

Info : Error in callService(). Please contact your Administrator.

Info : System.ComponentModel.Win32Exception: Not enough quota is available to process this command

   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

   at OCRonUploadDoc.EventReceiver1.EventReceiver1.callService()

=========================================

我无法弄清楚这个问题。请帮帮我...... !!!

先谢谢。

  • Khan Abubakar

1 个答案:

答案 0 :(得分:0)

我认为运行应用程序池的asp.net帐户没有启动exe文件的权限。你可以查看http://www.daniweb.com/web-development/aspnet/threads/386380/cannot-run-exe-files-in-asp.net-application 但是,如果您的系统将被更多用户使用,您可能会很快遇到问题,因为文档的每次更改都会产生一个新进程。服务器将用完RAM并且服务器场将不可用。

相关问题