简体   繁体   中英

How do you use process.start() to call an external .exe

private void LaunchLAIFOMSApplication(string pApplicationName, string pCommandLineArgs)
        {
            try
            {
                this._laifomsProcesses.Add(pApplicationName);
                pApplicationName = pApplicationName + ".exe";
                ProcessStartInfo process = new ProcessStartInfo();
                process.WorkingDirectory =Application.StartupPath;
                process.FileName = pApplicationName;
                process.Arguments = pCommandLineArgs;
                process.UseShellExecute = false;
                process.CreateNoWindow = false;
                Process.Start(process);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message + "." + Environment.NewLine + "Please contact the Systems Administrator.", "LAIFOMS Application", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }

您应该为process.FileName应用程序的完整路径,而不仅仅是应用程序名称

You can do

ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\MyApplication.exe");
Process.Start(startInfo);

You need to provide the full path of your application. And if you want to close the running exe after you run the new exe, do this

Process.GetCurrentProcess().Kill();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM