locked
EWS, MSG.exe and Windows Services RRS feed

  • Question

  • Task is to send notification to a user whenever an email arrives into a public folder. I created a windows service with EWS subscription service and whenever NewMail or Created event occurs, the OnEvent creates a MSG command to send a notification to the user that email is waiting for him in the public folder.

    For sending the notification I am using the Process class:

    string sCMD = @"MSG.exe " + user + " /Server " + pc + " /Time 0 " + msg

    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                    startInfo.FileName = "cmd.exe";
                    startInfo.Arguments = "/c " + sCMD;
                    startInfo.UseShellExecute = false;
                    startInfo.CreateNoWindow = true;
                    startInfo.RedirectStandardError = true;

                    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo = startInfo;
                  
                    proc.Start();
                    string error = proc.StandardError.ReadToEnd();
                    proc.WaitForExit();

    I am receiving the following error message:

    ‘MSG' is not recognized as an internal or external command, operable program or batch file.

    When I ran the same function from a forms application, it works. When I copied it to the Windows Services application, it is throwing the above error.  Any light on how to fix this  will be of great help.

    Appreciate your help.

    Sunday, January 12, 2014 3:44 PM

Answers

  • It worked when I gave the filename as MSG.exe

    startInfo.FileName = "msg.exe";

    • Marked as answer by ysku Monday, July 21, 2014 4:57 PM
    Monday, July 21, 2014 4:56 PM

All replies

  • The error is telling you that it can't find the file in question so it means the file isn't in the path in question (You haven't specified a path to the file so its going to use the default for the service) or the account your service is running under doesn't have permissions to that path/file. You might want to try specifying the whole path or use some of the other solutions metioned in http://stackoverflow.com/questions/17857225/why-does-process-startprocessstartinfo-fail .

    Cheers
    Glen

     
    Monday, January 13, 2014 3:19 AM
  • It worked when I gave the filename as MSG.exe

    startInfo.FileName = "msg.exe";

    • Marked as answer by ysku Monday, July 21, 2014 4:57 PM
    Monday, July 21, 2014 4:56 PM