我有这段代码:
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = "rdpclip.exe";
myProcess.Start();
启动位于system32
中的exe文件我总是收到错误,找不到系统文件。在Windows 2008服务器中。
即使我设置了StartupInfo.FileName =“c:\\ windows \\ system32 \\ rdpclip.exe”,它仍然找不到该文件!?
如果我将文件放在其他文件夹中,它会起作用,但在System32中它无法启动。我只需要杀死这个过程并重新开始,但是我从没想过在C#中做这么简单的事情真的很痛苦吗?!
答案 0 :(得分:4)
此错误具有误导性,因为它通常意味着您没有该文件夹的权限。尝试构建您的程序,然后右键单击生成的.exe并单击“以管理员身份运行”。
答案 1 :(得分:3)
试试这个(你需要导入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);
}