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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With