【问题标题】:Not able to launch narrator from Visual Studio无法从 Visual Studio 启动讲述人
【发布时间】:2017-05-30 13:42:44
【问题描述】:

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

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

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

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

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

【问题讨论】:

  • 请发布异常或您得到的任何输出。
  • @Szer 发布了异常
  • 这是非常明显的错误信息。是否存在“C:\windows\system32\narrator.exe”?
  • 文件在那里,因为它是由于 Windows 的文件系统重定向,这个错误不断出现我无法找到解决它的方法@Szer

标签: c# exe narrator


【解决方案1】:

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

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);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多