0

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

代码:

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()

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

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

提前致谢。

  • 汗阿布巴卡尔
4

1 回答 1

0

I think that the asp.net account under which the application pool runs does not have permissions to start the exe file. You can check this out http://www.daniweb.com/web-development/aspnet/threads/386380/cannot-run-exe-files-in-asp.net-application However if your system will be used by more users you can run into problems really quickly, because every change of a document will spawn a new process. The server will run out of ram and the farm will not be unavailable.

于 2012-05-10T06:46:25.360 回答