Process.Start in the Windows \ System32 folder

Trying to run a file located in System32 as an administrator, but he continues to tell me that it does not exist.

Error: the system cannot find the specified file. Assembly platform: x86. Current OS: Windows 8.1 x64. I would prefer not to have 2 different .exe for 32 and 64 bit os.

p.StartInfo.Verb = "runas";
p.StartInfo.FileName =
    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System),"Defrag.exe");
    //above points to c:\windows\system32\defrag.exe
p.StartInfo.Arguments = @"c:\ /A";
p.Start();
p.WaitForExit();

I also tried the following with no luck

p.StartInfo.FileName = 
    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "sysnative", "Defrag.exe");

Update

Switching the application from x86 to any processor fixed the problem

0
source share
1 answer

, 64- . , Environment.SpecialFolder.System C:\Windows\SysWOW64 64- . SysWOW64 , "Defrag.exe" .

  i.e Process.Start(@ "C:\Windows\System32\defrag.exe" )

:

< > Path = Environment.Is64BitOperatingSystem    ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "Defrag.exe" )    : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "Defrag.exe" ) >

+3

Source: https://habr.com/ru/post/1627440/


All Articles