8

我创建了一个带有很多按钮的 WPF 窗口,每个按钮都运行不同的程序。例如,要运行 MS Word,我使用了:

System.Diagnostics.Process.Start("C:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE");

但是当我尝试以同样的方式运行 Windows 7 Snipping Tool 时,它不起作用。它应该是这样的:

System.Diagnostics.Process.Start("C:\\Windows\\System32\\SnippingTool.exe");

我确定路径是正确的,但总是出现一条消息说找不到文件。我想知道为什么会这样。

重要提示:我使用的是 Windows 7 64 位。

4

3 回答 3

10

用这个:

// if the build platform of this app is x86 use C:\windows\sysnative
if(!Environment.Is64BitProcess) 
   System.Diagnostics.Process.Start("C:\\Windows\\sysnative\\SnippingTool.exe");
else
   System.Diagnostics.Process.Start("C:\\Windows\\system32\\SnippingTool.exe");

问题在于您的构建平台 (x86) 和C:\Windows\System32\64 位操作系统上文件夹的自动重定向。

基本上,出于多种原因,在 vista/windows 7 64 位操作系统中,当 32 位应用程序尝试访问C:\Windows\System32\它时,它会自动重定向到名为C:\Windows\SysWOW64\. 因此,您无法启动snippingtool.exe,因为它不存在于该文件夹中。

唯一的方法是使用C:\Windows\sysnative\并绕过重定向。

于 2012-07-31T17:46:01.597 回答
3

我的通灵调试器告诉我,您正在 64 位版本的 Windows 上运行 32 位程序,因此您对%WINDIR%( C:\Windows) 的调用实际上被重新路由到C:\Windows\SysWOW64.

使用环境变量而不是硬编码路径到可能会根据环境和/或 Windows 版本移动的目录。

于 2012-07-31T17:24:35.677 回答
2

您应该改用环境变量。很可能您在 64 位系统上运行它C:\Windows\System32\并被重定向。

于 2012-07-31T17:24:20.857 回答