Process.start does not open osk.exe in C#

Asked

Viewed 218 times

3

I’m using the Process.start() to open some system applications, however despite working properly for the notepad and for the calculator, when I try to open the screen keyboard (osk.exe) the program has an abrupt termination and gives the following error:

"The system cannot find the especified file"

The code I have is this::

private void calculadoraToolStripMenuItem_Click(object sender, EventArgs e)
{
    Process.Start("calc.exe");
}

private void blocoDeNotasToolStripMenuItem_Click(object sender, EventArgs e)
{
    Process.Start("notepad.exe");
}

private void tecladoNoEcrãToolStripMenuItem_Click(object sender, EventArgs e)
{
    Process.Start("osk.exe");
}
  • Open a Powershell prompt and type [diagnostics.process]::Start("osk.exe"). What is the result?

  • in Powershell works... curious pq inside the C#, even putting FileInfo file = new FileInfo("C:\\Windows\\System32\\osk.exe"); shows that the file does not exist. It must be a security issue

  • @Augustall if I try to run this code in Powershell the application runs, however, in C# this does not have the same effect.

  • From inside the interactive c# prompt(csi.exe) I managed to call the osk.exe. I used the lines: > using System.Diagnostics; and > Process.Start("osk.exe");. I will open an instance of Visual Studio.

  • Here works of good

  • @Leandroangelo did it in visual studio or Powershell?

  • 1

    @Leandroangelo No visual studio does not work. Error image , conversion of hresult , OS error table

  • 1

    @Rovannlinhalis, I found the problem.

Show 3 more comments

1 answer

7


The problem is occurring because the process osk.exe is a 64-bit process.

By default a Visual Studio application is compiled for 32-bit platforms to ensure greater compatibility, the problem is that this type of application can only boot 32-bit processes as well.

To solve the problem you need to compile a 64-bit application.

  • Open the properties of your project:

propriedades do projeto

  • On the tab Build in Platform Target: select x64

Selecionar plataforma

  • Only compile and run:

Código funcionando

  • 1

    That’s right, I was going to even comment that I had run on C# Interactive (64-bit)

  • @Leandroangelo on CSI and Powershell it works smoothly. The problem is specific x86 VS platform whose assembly System.Diagnostics connected in the code cannot open a 64-bit application.

  • 1

    @Augustovasques It worked, thank you very much!

  • 1

    @Duochannelyt, you have to thank me, no, it was fun hunting the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.