1

我需要通过我的 MVC 控制器运行应用程序。为了获得我使用以下链接的安装路径(我使用了 Fredrik Mörk 提供的答案)。它有效,我可以通过一个进程运行 exe。当我在 IIS 上部署此解决方案时出现问题,它没有像在本地开发环境中创建进程那样创建进程。谁能告诉我如何通过托管在 IIS 上的解决方案创建 Windows 进程?

    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();
        }
    }
4

0 回答 0