locked
Run program from Plug-in RRS feed

  • Question

  • Hi everyone.

    Since last week I have a new problem.
    I have written a plugin that calls a .exe which must generates scheduled tasks within the CRM server, this is part of my code:

    if (context.OutputParameters.Properties.Contains("id"))
                    {
                        string argumento = context.OutputParameters.Properties["id"].ToString();
                        String userName = "Administrator";
                        String password = "correctPassword";
                        String domain  = "MyDomain";
                        System.Security.SecureString pwdString = new System.Security.SecureString();
    
                        foreach (Char c in password)
                        {
                            pwdString.AppendChar(c);
                         }
                            try
                            {
                                System.Diagnostics.Process process = new System.Diagnostics.Process();
                                process.StartInfo.LoadUserProfile = true;
                                process.StartInfo.Arguments = argumento;
                                process.StartInfo.FileName = @"C:\Program Files\Tarea\Tarea.exe";
                                process.StartInfo.UseShellExecute = false;
                                process.StartInfo.UserName = userName;
                                process.StartInfo.Password = pwdString;
                                process.StartInfo.Domain = domain;                           
                                process.Start();
                                process.WaitForExit();
                            }
    
                            catch (Exception ex) {throw new InvalidPluginExecutionException("Ha ocurrido un error al ejecutar el programa Tarea.exe: " + ex.Message.ToString(), ex); }
                    }


    So my plug-in calls a .exe program that actually uses a library called TaskScheduler.dll that I downloaded from this site:

    http://www.codeproject.com/KB/cs/tsnewlib.aspx

    So, I need my plug-in generates scheduled tasks using another program called tarea.exe.
    If call tarea.exe from the command prompt, passing the correct parameters tarea.exe works, but when I do it from the Plug-in does not.
    To me, this happens because calling tarea.exe within my plug-in is executed by NETWORK SERVICE ACCOUNT which does not have rights to create scheduled tasks on my server. That's why I especify user:

                                process.StartInfo.LoadUserProfile = true;
                                process.StartInfo.Arguments = argumento;
                                process.StartInfo.FileName = @"C:\Program Files\Syndeo\Tarea\Tarea.exe";
                                process.StartInfo.UseShellExecute = false;
                                process.StartInfo.UserName = userName;
                                process.StartInfo.Password = pwdString;
                                process.StartInfo.Domain = domain;   


    The problem about running tarea.exe  as Administrator is that I can see tarea.exe in the task manager but only for a moment and then it finish without a warning or error and obviously without create my scheduled tasl. Then I check out event viewer and I can see the following error:

    Application Error:
    Tarea.exe Faulting application, version 1.0.0.0, time stamp 0x4b63321d, faulting module KERNEL32.dll, version 6.0.6002.18005, time stamp 0x49e037dd, 0xc06d007e exception code, fault offset 0x0003fbae, process id 0x6e0, application start time 0x01caa1339a791170.

    So I wonder if I'm using either the class process, even if it is possible to make what I am saying: call tarea.exe with user Administrator from a plug-in that was run by NETWORK SERVICE ACCOUNT.

    Have an idea?

    Thank you.
    Tuesday, February 2, 2010 7:43 AM

Answers

  • I finally solved my problem.
    I'll write the way I solved it and hopefully someone will serve. 
    I used .Net Remoting, that's how I got it. I was trying to run Tarea.exe from the Plug-in but now I do it from an application that receives a request for it. The application that sends the request is a little application that is launched bye the plug-in. In short: When creating a new incident in the CRM executes the Plug-in then within I execute Master.exe who sends a request to Slave.exe (running all the time as a service) who finally launches Tarea.exe and create the scheduled task (which is running with LOCALSYSTEM permissions).

    Thanks.
    Friday, February 5, 2010 9:57 PM

All replies

  • I finally solved my problem.
    I'll write the way I solved it and hopefully someone will serve. 
    I used .Net Remoting, that's how I got it. I was trying to run Tarea.exe from the Plug-in but now I do it from an application that receives a request for it. The application that sends the request is a little application that is launched bye the plug-in. In short: When creating a new incident in the CRM executes the Plug-in then within I execute Master.exe who sends a request to Slave.exe (running all the time as a service) who finally launches Tarea.exe and create the scheduled task (which is running with LOCALSYSTEM permissions).

    Thanks.
    Friday, February 5, 2010 9:57 PM
  • Hi Ricardo,

    I am also facing the same problem as you mentioned while using the Task Schduler.dll in the MSCRM Plugin .

    Though I register TaskScheduler.dll in  GAC, I am not able to CreateTask in the Windows Scheduler.  Can you please  explain me in detail regarding the implementation ?

    Did you create Master.exe & Slave.exe as Console applications ?  Can you be able to help me with the code  implemented ?

    Thanks & Regards,

    KRithika

     

     

    Friday, March 18, 2011 9:25 AM