Process.Start in C# The system cannot find the file specified error
Most likely your app is 32-bit, and in 64-bit Windows references to C:\Windows\System32
get transparently redirected to C:\Windows\SysWOW64
for 32-bit apps. calc.exe
happens to exist in both places, while soundrecorder.exe
exists in the true System32
only.
When you launch from Start / Run
the parent process is the 64-bit explorer.exe
so no redirection is done, and the 64-bit C:\Windows\System32\soundrecorder.exe
is found and started.
From File System Redirector:
In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64.
[ EDIT ] From the same page:
32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32.
So the following would work to start soundrecorder.exe
from the (real) C:\Windows\System32
.
psStartInfo.FileName = @"C:\Windows\Sysnative\soundrecorder.exe";
Error in Process.Start() -- The system cannot find the file specified
Try to replace your initialization code with:
ProcessStartInfo info
= new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.exe");
Using non full filepath on Process.Start
only works if the file is found in System32 folder.
The system cannot find the file specified error on process.Start();
I suspect the problem is that the filename you're specifying is relative to your working directory, and you're expecting Process.Start
to look there when starting the process - I don't believe it works that way when UseShellExecute
is false
. Try just specifying the absolute filename of the process you want to start:
process.StartInfo.FileName = @"C:\Projects\MyProgram.exe";
Note that I've also removed the space from the end of the string you were assigning for the FileName
property - it's entirely possible that was casuing the problem too.
Process.Start(...) throws The system cannot find the file specified
You shouldn't have to call cmd.exe /c, you should be able to run taskkill.exe directly.
This works on my machine (windows 10).Do you need to search for the files every time? I think for a simple utility app, having the paths hard coded should be fine.
var startInfo = new ProcessStartInfo()
{
Verb = "runas",
Arguments = "/f /im explorer.exe",
FileName = @"c:\windows\system32\taskkill.exe"
};
var process = new Process { StartInfo = startInfo };
process.Start();
process.WaitForExit();
startInfo = new ProcessStartInfo()
{
Verb = "runas",
FileName = @"C:\windows\explorer.exe"
};
process = new Process { StartInfo = startInfo };
process.Start();
Process.Start() can't find file?
The reason that Chrome.exe & Devenv.exe are running automatically is that for both applications their paths (folders where they reside) are declared in the system Path
environment variable.
There are 2 solutions for that.
You have to either call your Discoord.exe application by setting the full path of it, eg:
Process.Start("C:\\Users\\AppData\\Local\\Discord\\app-0.0.307\\Discord.exe");
Set the environment Path in the system of your computer. eg. look the bellow screen-shot:
Process.Start(): The system cannot find the file specified, but my file path seems to be legit
This is down to the file system redirector. You will be running a 32 bit process on a 64 bit machine. That means that C:\Windows\system32
is transparently redirected to C:\Windows\SysWOW64
and I expect that du.exe
cannot be found there. If you use C:\Windows\Sysnative
instead then you will be able to locate the file.
However, I suspect that you have added du.exe
to the system directory since this is not a standard Windows component. You should not do that. I recommend you put the file somewhere else because you simply should not be writing in the system directory.
Related Topics
Double Buffering When Not Drawing in Onpaint(): Why Doesn't It Work
Why Can't I Use System.Io.File Methods in an MVC Controller
Wpf: How to Override Part of a Controltemplate Without Redefining the Whole Style
How to Restrict/Control the Navigation Routes the User Can Visit Based on Login Status/Role
Outofmemoryexception While Populating Memorystream: 256Mb Allocation on 16Gb System
Zoom and Translate an Image from the Mouse Location
How to Post a List of Items in MVC
Why Was "Switchto" Removed from Async Ctp/Release
Using Layers and Bitmask with Raycast in Unity
Is There a Generic Constraint I Could Use for the + Operator
Windows.Ui.Notifications Is Missing
How to Check If Ienumerable Is Null or Empty
Why Is There No Char.Empty Like String.Empty
"Updatesourcetrigger=Propertychanged" Equivalent for a Windows Phone 7 Textbox
Web API 2: How to Return JSON with Camelcased Property Names, on Objects and Their Sub-Objects