简体   繁体   中英

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?

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.

在此处输入图片说明

More information could be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM