Creating a process in ASP.NET MVC controller

Posted by GRKamath on Stack Overflow See other posts from Stack Overflow or by GRKamath
Published on 2012-08-31T07:44:53Z Indexed on 2012/08/31 9:38 UTC
Read the original article Hit count: 178

Filed under:
|
|

I have a requirement to run an application through my MVC controller. To get the installation path I used following link (I used answer provided by Fredrik Mörk). It worked and I could able to run the exe through a process. The problem occurred when I deployed this solution on IIS where it did not create the process as it was creating in local dev environment. Can anybody tell me how to create a windows process through a solution which is hosted on IIS ?

    private string GetPathForExe(string fileName)
    {
        private const string keyBase = @"SOFTWARE\Wow6432Node\MyApplication";
        RegistryKey localMachine = Registry.LocalMachine;
        RegistryKey fileKey = localMachine.OpenSubKey(string.Format(@"{0}\{1}", keyBase, fileName));
        object result = null;
        if (fileKey != null)
        {
            result = fileKey.GetValue("InstallPath");
        }
        fileKey.Close();
        return (string)result;
    }

    public void StartMyApplication()
    {
        Process[] pname = Process.GetProcessesByName("MyApplication");
        if (pname.Length == 0)
        {
            string appDirectory = GetPathForExe("MyApplication");

            Directory.SetCurrentDirectory(appDirectory);
            ProcessStartInfo procStartInfo = new ProcessStartInfo("MyApplication.exe");
            procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            Process proc = new Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
        }
    }

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about iis