2008-10-27 12 views

Respuesta

50
System.Diagnostics.Process.Start("PathToExe.exe"); 
+0

¿Qué pasa si no sé el nombre completo del exe, quiero llamar "PathTo * .exe" ¿Es esto posible? – vishal

196

He aquí un fragmento de código útil:

using System.Diagnostics; 

// Prepare the process to run 
ProcessStartInfo start = new ProcessStartInfo(); 
// Enter in the command line arguments, everything you would enter after the executable name itself 
start.Arguments = arguments; 
// Enter the executable to run, including the complete path 
start.FileName = ExeName; 
// Do you want to show a console window? 
start.WindowStyle = ProcessWindowStyle.Hidden; 
start.CreateNoWindow = true; 
int exitCode; 


// Run the external process & wait for it to finish 
using (Process proc = Process.Start(start)) 
{ 
    proc.WaitForExit(); 

    // Retrieve the app's exit code 
    exitCode = proc.ExitCode; 
} 

Hay mucho más que puede hacer con estos objetos, usted debe leer la documentación: ProcessStartInfo, Process.

+6

Solo quería señalar que esto también parece funcionar con otros tipos de archivos que .exes. Simplemente señale el archivo que desea abrir y Windows hará todo lo posible para abrirlo: System.Diagnostics.Process.Start (@ "C: \ Users \ Blank \ Desktop \ PdfFile.pdf"); – DLeh

+0

WindowStyle = ProcessWindowStyle.Hidden es para no GUI.La primera vez que ejecuté esto falló sin UseShellExecute = false, pero funciona ahora. No estoy seguro de lo que está pasando allí ... – Barton

+0

A decir verdad, nunca he intentado esto con una aplicación GUI. – sfuqua

18
System.Diagnostics.Process.Start(@"C:\Windows\System32\Notepad.exe"); 
13

Si tiene problemas al usar System.Diagnostics como si tuviera, utilice el siguiente código simple que funcionará sin él:

Process notePad = new Process(); 
notePad.StartInfo.FileName = "notepad.exe"; 
notePad.StartInfo.Arguments = "mytextfile.txt"; 
notePad.Start(); 
+5

¿Cómo es esto "sin System.Diagonostics"? 'Process' está en System.Diagnostics. –

0

Uso Process.Start para iniciar un proceso.

using System.Diagnostics; 
class Program 
{ 
    static void Main() 
    { 
    // 
    // your code 
    // 
    Process.Start("C:\\process.exe"); 
    } 
} 
0

acaba de poner su file.exe en la carpeta \ Debug \ bin y uso:

Process.Start("File.exe"); 
+0

¿Cómo mejora tu respuesta en todas las anteriores? – mustaccio

1

Prueba esto:

Process.Start("Location Of File.exe"); 

(Asegúrese de que utiliza la biblioteca System.Diagnostics)

-1

Adame Kane

System.Diagnostics.Process.Start(@"C:\Windows\System32\Notepad.exe"); 

esto funcionó muy bien !!!!!

Cuestiones relacionadas