C# 为什么进程会自动在桌面上查找my.exe?如何指定固定/非灵活路径?

C# 为什么进程会自动在桌面上查找my.exe?如何指定固定/非灵活路径?,c#,C#,我以通常的方式启动可执行文件: Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.WorkingDirectory = @"C:\someDirectory\"; p.StartInfo.FileName = "ConsoleProgram.exe"; p.Start(); 当前,可执行文件不在C:\some

我以通常的方式启动可执行文件:

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WorkingDirectory = @"C:\someDirectory\";
p.StartInfo.FileName = "ConsoleProgram.exe";
p.Start();
当前,可执行文件不在C:\someDirectory\中,因此我希望上述操作失败,因为找不到可执行文件

相反,它所做的是,出于某些原因,它在我的桌面上以相同的名称找到不同的可执行文件!我知道这一点,因为如果我在桌面上重命名.exe,软件会抱怨找不到.exe。如何防止这种行为,并强制执行特定路径而不执行其他路径?

是否尝试将文件名设置为文件的路径? 像这样:

p.StartInfo.FileName = @"C:\someDirectory\ConsoleProgram.exe";
您是否尝试将文件名设置为文件的路径? 像这样:

p.StartInfo.FileName = @"C:\someDirectory\ConsoleProgram.exe";

将完整路径信息添加到文件名。

将完整路径信息添加到文件名

当UseShellExecute为false时,WorkingDirectory属性不为false 用于查找可执行文件。相反,它被 已启动,并且仅在新流程的上下文中具有意义

在这里,您将UseShellExecute设置为false,WorkingDirectory完全没有意义,因此您必须使用绝对路径作为文件名

当UseShellExecute为false时,WorkingDirectory属性不为false 用于查找可执行文件。相反,它被 已启动,并且仅在新流程的上下文中具有意义


在这里,您将UseShellExecute设置为false,WorkingDirectory完全没有意义,因此您必须使用绝对路径作为文件名

可能桌面在path env变量中?可能桌面在path env变量中?