C#代码启动Windows Mobility Center失败,求正确实现方案
解决Windows Mobility Center(mblctr.exe)启动失败的问题
核心原因是64位Windows系统的文件重定向机制:32位应用程序访问C:\Windows\System32时,会被系统自动重定向到C:\Windows\SysWOW64目录,但mblctr.exe仅存在于64位的System32目录下,因此会出现“文件未找到”的错误。
以下是三种可行的解决方案:
方案1:使用Sysnative路径直接访问64位System32
System.Diagnostics.Process.Start(@"C:\Windows\Sysnative\mblctr.exe");
Sysnative是系统提供的虚拟路径,专门用于32位程序访问64位的System32目录。
方案2:临时禁用文件系统重定向(适合多文件访问场景)
using System; using System.Diagnostics; using System.Runtime.InteropServices; public class MobilityCenterLauncher { [DllImport("kernel32.dll", SetLastError = true)] private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr); [DllImport("kernel32.dll", SetLastError = true)] private static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr); public static void Launch() { IntPtr redirectPtr = IntPtr.Zero; try { // 禁用重定向 if (Wow64DisableWow64FsRedirection(ref redirectPtr)) { Process.Start(@"C:\Windows\System32\mblctr.exe"); } } finally { // 必须恢复重定向,避免影响后续操作 if (redirectPtr != IntPtr.Zero) { Wow64RevertWow64FsRedirection(redirectPtr); } } } }
方案3:通过ShellExecute启动(利用系统shell解析路径)
var startInfo = new System.Diagnostics.ProcessStartInfo { FileName = "mblctr.exe", UseShellExecute = true }; System.Diagnostics.Process.Start(startInfo);
开启UseShellExecute = true后,会让系统shell负责路径解析,自动绕过重定向问题。
额外说明
如果你的程序是64位编译的,直接使用你最初的代码System.Diagnostics.Process.Start(@"C:\Windows\System32\mblctr.exe")即可正常运行,无需任何额外处理。
内容的提问来源于stack exchange,提问作者Jack Pomi
相关产品推荐
相关产品推荐

