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
  •  | 
  •  

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)"

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top