Search code examples
c#.netoutlook-2013

Launch outlook 2013 from C# code


How can I close and open outlook 2013 programmatically using C# ?

Here is the problem that I am trying to solve. I have set up an automatic backup of my .pst files to a external hard drive. I am using the free software 'SyncBackFree' for the backup. The issue is the back up fails because the .pst file is open in outlook. I am thinking of developing a windows service that will shut down outlook at a fixed time and after 20 minutes or so, will launch the outlook again. I could not find any documentation to shut down and launch outlook. I tried looking at Launch Outlook to compose a message with subject and attachment by Outlook's command line switches

Please advise.


Solution

  • You can try to kill process and launch it later.

    Something like this :

    kill

    foreach (var process in Process.GetProcessesByName("outlook.exe"))
    {
        process.Kill();
    }
    

    launch (don't forget to set pathOutlook)

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = Path.Combine(pathOutlook, "outlook.exe");
    startInfo.WorkingDirectory = pathOutlook ;
    Process p = Process.Start(startInfo);