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