无法从 Visual Studio 启动讲述人

Not able to launch narrator from Visual Studio

我无法使用 C# 从 Visual Studio 启动旁白程序。我试过使用完整路径和其他类似的技巧但没有结果? 代码是:

System.Diagnostics.Process.Start(@"C:\windows\system32\narrator.exe");

类似的代码能够执行同一文件夹中的 notepad.exe。任何人都可以在这方面帮助我吗? 我得到的执行是 ::

“System.dll 中发生了 'System.ComponentModel.Win32Exception' 类型的未处理异常 附加信息:系统找不到指定的文件“

但是文件存在于指定路径中。 然后我将整个 system32 文件夹复制到我的桌面并提供了新位置。然后代码毫无例外地通过但没有启动旁白应用程序。

您可以使用一些系统调用禁用文件系统重定向。请注意,即使重定向已修复,您仍然无法在没有提升权限的情况下启动讲述人。

const int ERROR_CANCELLED = 1223; //The operation was canceled by the user.

var oldValue = IntPtr.Zero;
Process p = null;

try
{
    if (SafeNativeMethods.Wow64DisableWow64FsRedirection(ref oldValue))
    {
        var pinfo = new ProcessStartInfo(@"C:\Windows\System32\Narrator.exe")
        {
            CreateNoWindow = true,
            UseShellExecute = true,
            Verb = "runas"
        };

        p = Process.Start(pinfo);
    }

    // Do stuff.

    p.Close();

}
catch (Win32Exception ex)
{
    // User canceled the UAC dialog.
    if (ex.NativeErrorCode != ERROR_CANCELLED)
        throw;
}
finally
{
    SafeNativeMethods.Wow64RevertWow64FsRedirection(oldValue);
}


[System.Security.SuppressUnmanagedCodeSecurity]
internal static class SafeNativeMethods
{
    [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);

}