2012-11-12 20 views
5

Process.Start non riesce a trovare un file esistente

  • Ho il percorso di un file eseguibile (C:\Test\n4.TestConsole.exe).
  • File.Exists(path) restituisce true.
  • File.OpenRead(path) mi ottiene il suo flusso senza alcun problema.
  • Process.Start(path) getta un System.ComponentModel.Win32Exception con questo messaggio:

    Il sistema non trova il file specificato.

Cosa sto sbagliando?

Windows 8 Professional x64 - .NET Framework 4,5


Edit: Ecco il codice.

public partial class Form1 : Form 
{ 
    public string Path { get; set; } 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     // I put a breakpoint here and verify the Path's value is 
     // C:\Test\n4.TestConsole.exe. 

     // File.Exists returns true. 
     MessageBox.Show(File.Exists(Path)); 

     // File.OpenRead doesn't throw an exception. 
     using (var stream = File.OpenRead(Path)) { } 

     // This throws the exception. 
     Process.Start(Path); 
    } 
} 
+0

Qual è il tipo di file che si sta tentando di eseguire? È "eseguibile"? Puoi mostrare il valore del percorso? –

+0

@WouterdeKort: un'applicazione console. Si apre e attende un input quando faccio doppio clic su di esso. Il percorso è: 'C: \ Test \ n4.TestConsole.exe' –

+0

Qual è il valore del percorso? È necessario utilizzare il percorso completo del file se il file non è in System32 –

risposta

2

Probabilmente è una DLL mancante o altra dipendenza. Potresti voler confrontare la variabile d'ambiente PATH quando la esegui direttamente tramite Process.Start(exe_path) e quando la esegui tramite Process.Start("cmd", "/k " + exe_path).

1

Prova questo:

private void button1_Click(object sender, EventArgs e) 
{ 
    ProcessStartInfo psi = new ProcessStartInfo(); 
    psi.WorkingDirectory = @"C:\Test"; 
    psi.FileName = "n4.TestConsole.exe"; 
    Process.Start(psi); 
} 
Problemi correlati