C # Cannot start system exe process

I have this code:

Process myProcess = new Process(); myProcess.StartInfo.UseShellExecute = true; myProcess.StartInfo.FileName = "rdpclip.exe"; myProcess.Start(); 

to run an exe file that is in system32

I always get an error that the system file was not found. In a Windows 2008 server.

Even if I set StartupInfo.FileName = "c: \\ windows \\ system32 \\ rdpclip.exe", it still won’t find the file !?

It works if I put the file in another folder, but it does not start in System32. I just need to kill this process and start again, but I never thought that C # had such pain to do such a simple thing ?!

+4
source share
2 answers

This error is misleading, as it usually means that you do not have permission to this folder. Try to create your program, then right-click the resulting .exe file and click "run as administrator".

+4
source

Try this (you will need to import System.Runtime.InteropServices):

 [DllImport("kernel32.dll", SetLastError = true)] public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr); IntPtr ptr = IntPtr.Zero; if(Wow64DisableWow64FsRedirection(ref ptr)) { Process myProcess = new Process(); myProcess.StartInfo.UseShellExecute = true; myProcess.StartInfo.FileName = "rdpclip.exe"; myProcess.Start(); Process.Start(myProcess); Wow64RevertWow64FsRedirection(ptr); } 
+3
source

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


All Articles