Misaz
Misaz

Reputation: 3985

C# can't see windows program

I am creating a program that has to work with Windows system programs like a C:\windows\System32\bcdedit.exe. If I try to reach for example mspaint it works good.

IO.File.Exists(@"C:\windows\System32\mspaint.exe") // return true

but

IO.File.Exists(@"C:\windows\System32\bcdedit.exe") // return false

This returns false but the file really exists. I can see it in windows explorer and I can start it from the command line. Only for my c# application is this file unreachable. When I want to start it I get the error Win32Exception with the message:

The system cannot find the file specified

And when I "ask" if the file exists (by code above) it returns false.

Why?

Upvotes: -1

Views: 246

Answers (1)

casillas
casillas

Reputation: 16793

Try the following, this should return true.

IO.File.Exists(@"C:\windows\System32\bcdedit.exe");

Here is an example to test:

string curFile = @"C:\windows\System32\bcdedit.exe";
Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");

Reference:https://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx

If that does not work, then most likely issue is x64 or x86. Therefore you should configure your build to AnyCPU and test it again.

enter image description here

More information could be found here.

Upvotes: 0

Related Questions