简体   繁体   中英

C# Cannot start a system EXE process

I have this code:

 Process myProcess = new Process();

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

to start an exe file which is located in system32

I always get an error that, the system file cannot be found. In windows 2008 server.

Even if I set the StartupInfo.FileName="c:\\\\windows\\\\system32\\\\rdpclip.exe" it still does not find the file !?

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

This error is misleading because it usually means you to do not have permission to that folder. Try building your program, then right click the resulting .exe and click 'run as administrator'.

Try this (you'll 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);    
}

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