System cannot find the file specified when I try to call an executable file in C#

StackOverflow https://stackoverflow.com/questions/20530089

  •  31-08-2022
  •  | 
  •  

Pregunta

I'm running a C# script in SSIS. In that script, I'm trying to call winSCP.com which is located in the following directory: "C:\Program Files (86)\WinSCP\"

But when I try to run the code, it always fails immediately.
Here is my code. what am I doing wrong?

// Run hidden WinSCP process

Process winscp = new Process();
winscp.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\WinSCP\\";
winscp.StartInfo.FileName = "winSCP.com";
winscp.StartInfo.UseShellExecute = false;
winscp.StartInfo.RedirectStandardInput = true;
winscp.StartInfo.RedirectStandardOutput = true;
winscp.StartInfo.CreateNoWindow = true;
winscp.Start();

The Error: "System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)"

¿Fue útil?

Solución

winscp.StartInfo.FileName = "C:\\Program Files (x86)\\WinSCP\\WinSCP.com";

Otros consejos

When you do not use shell execute. You must use the full path to the executed file. Because that in this case the working directory is not base directory to relative path. But just working folder for the executed file.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top