1

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();
        }
    }
Community
  • 1
  • 1
GR Kamath
  • 65
  • 1
  • 7
  • Wouldn't Windows Service be a better approach? – Jakub Konecki Aug 31 '12 at 07:47
  • 1
    Welcome to Stackoverflow. Please only post the code necessary to understand the question. And please don't post unnecessary comments like that autodoc stuff. I have removed it for your convenience. – Dennis Traub Aug 31 '12 at 07:48
  • This is not a great idea. What's the rationale behind it? IIS by default runs as a service user - not interactive, therefore if you did get it to execute an application, the application would be running server-side and without any user interaction. Is this the intended behaviour? – Matthew Abbott Aug 31 '12 at 09:50
  • Yes. I want my application (MyApplication.exe) to be run on server side. Now I just want to know is there any work around with which I can make my application to run on server side. – GR Kamath Aug 31 '12 at 12:02
  • @JakubKonecki: Yes, Windows service will be another better option I was just wondering if this issue can be fixed ? because it works great in my local dev machine but not on IIS. I do not know whether I have to make changes in any IIS settings. – GR Kamath Aug 31 '12 at 12:26

0 Answers0