Trying to launch a file located in System32 as administrator but it keeps telling me it doesn\'t exist.
Error: System can\'t find specified file Build Target Platfor
Use Environment.SystemDirectory
:
string filePath = Path.Combine(Environment.SystemDirectory, "defrag.exe");
My guess would be that you are running this code on a 64-Bit Machine. If I remember correctly, the Environment.SpecialFolder.System variable returns C:\Windows\SysWOW64 on a 64-Bit machine. A quick search of the SysWOW64 Folder, and the error message is correct as "Defrag.exe" doesn't exist in the folder.
For test purposes, I would suggest something a bit simpler i.e Process.Start(@"C:\Windows\System32\defrag.exe")
Then you can use other variables to build your path based on the System Architecture:
String processPath = Environment.Is64BitOperatingSystem
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "Defrag.exe")
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "Defrag.exe")