2008-10-27 23 views

Antwort

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

Was ist, wenn ich den vollständigen Namen der exe nicht kenne, möchte ich "PathTo * .exe" aufrufen Ist das möglich? – vishal

196

Hier ist ein Ausschnitt von hilfreichen Code:

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; 
} 

Es gibt viel mehr ist, können Sie mit diesen Objekten zu tun, sollten Sie die Dokumentation lesen: ProcessStartInfo, Process.

+6

Ich wollte nur darauf hinweisen, dass dies auch mit anderen Dateitypen als .exes zu funktionieren scheint. Zeigen Sie einfach auf die Datei, die Sie öffnen möchten, und Windows wird versuchen, sie zu öffnen: System.Diagnostics.Process.Start (@ "C: \ Users \ Blank \ Desktop \ PdfFile.pdf"); – DLeh

+0

WindowStyle = ProcessWindowStyle.Hidden ist für nicht-GUI.Das erste Mal, dass ich das ausgeführt habe, ist es ohne UseShellExecute = false gescheitert, aber es funktioniert jetzt. Ich bin mir nicht sicher, was dort los ist ... – Barton

+0

Ehrlich gesagt habe ich das noch nie mit einer GUI-App versucht. – sfuqua

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

Wenn Sie Probleme mit System.Diagnostics haben, wie ich hatte, verwenden Sie die folgenden einfachen Code, der ohne es funktioniert:

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

Wie ist das "ohne System.Diagonostics"? 'Process' befindet sich in System.Diagnostics. –

0

Verwenden Process.Start einen Prozess zu starten.

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

setzen Sie Ihre file.exe in dem \ Debug-Ordner \ bin und verwenden:

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

Wie verbessert sich Ihre Antwort auf alle vorherigen? – mustaccio

1

Versuchen Sie folgendes:

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

(Stellen Sie sicher, dass Sie die System.Diagnostics-Bibliothek verwenden)

-1

Adame Kane

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

das hat super funktioniert !!!!!

Verwandte Themen