简体   繁体   中英

system.componentmodel.win32exception = {“the system cannot find the file specified”} error when opening narrator from c# in window 7

I am trying to open "narrator" screen reader in window 7 using c# and it

throws [system.componentmodel.win32exception] = {"the system cannot find the file specified"} exception.

Also I wrote a program to list all .exe files inside system32 dir and it does not show the Narrator. Why is this happening and how can I open narrator automatically using c#.

// trying to open opening narrator throws exception

ProcessStartInfo narratorProcessInfo = new ProcessStartInfo();            
try
{
    Console.WriteLine("Starting Narrator");
    Console.WriteLine("Opening time: " + DateTime.Now);

    narratorProcessInfo.FileName = "C:\\Windows\\system32\\Narrator.exe";

    using (Process narratorProcess = Process.Start(narratorProcessInfo))
    {
        narratorProcess.StartInfo.UseShellExecute = true;
        Console.WriteLine("Waiting for 5 seconds");
        Thread.Sleep(2000);
        narratorProcess.Kill();
    }
}
catch (Exception ex)
{
    Console.WriteLine("The exception message: "+ ex);
}
Console.WriteLine("Press any key to exit");
Console.ReadLine();

// listing all files in system32 directory but does not show narrator

Process pp = new Process();            
try
{
    string[] files = Directory.GetFiles(@"C:\Windows\System32"); // <-- Case-insensitive
    // Display all BIN files.
    Console.WriteLine("--- exe Files: ---");
    foreach (string name in files)
    {
        Console.WriteLine(name);
        Thread.Sleep(1000);
        if (name.Contains("Narrator"))
        {
             pp.StartInfo.FileName = name;
             pp.Start();
             Console.WriteLine("Waiting  5 sec");
             Thread.Sleep(5000);
             break;
        }
   }
}
catch (Exception ex)
{
     Console.WriteLine("The exception message: " + ex);
}            
Console.WriteLine("Press any key to exit");
Console.ReadLine();

From what I know, there's a redirection happening in the background when you're trying to directly access System32 processes in C#. You need to shut down the WOW redirection that prevents you from launching system processes.

Try this link, see if it helps you: WOW redirection deactivation in C#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM