Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从Visual Studio启动“讲述人”_C#_Exe_Narrator - Fatal编程技术网

C# 无法从Visual Studio启动“讲述人”

C# 无法从Visual Studio启动“讲述人”,c#,exe,narrator,C#,Exe,Narrator,我无法使用C#从Visual Studio启动“讲述人”程序。我尝试过使用complete path和其他类似的黑客,但没有结果? 代码是: System.Diagnostics.Process.Start(@"C:\windows\system32\narrator.exe"); 类似的代码可以执行同一文件夹中的notepad.exe。在这方面有人能帮我吗? 我得到的答案是: “System.dll中发生类型为'System.ComponentModel.Win32Exception'的未处

我无法使用C#从Visual Studio启动“讲述人”程序。我尝试过使用complete path和其他类似的黑客,但没有结果? 代码是:

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

}

请发布异常或您得到的任何输出。@Szer发布了异常,这是非常明显的错误消息。是否存在“C:\windows\system32\叙述者.exe”?由于windows的文件系统重定向,该文件存在。此错误不断出现,我无法找到解决方法@Szer