Run a Windows x64 application in C # when the project is set to x86

I try to start osk.exe, and I continue to receive the message "Cannot start osk". The problem is that my project is installed on x86 (I am using ms access database). If I switch to x64 or Any CPU, everything works fine, but the database no longer works. I tried this

using System.Diagnostics;

private void btnOSK_Click(object sender, EventArgs e)
    {   Process.Start("osk.exe");

        Process.Start(@"C:\windows\system32\osk.exe");
    }

I also tried to run SysWOWW \ osk, but that also did not work. In addition, my application should work on both x86 and x64 computers. Is there any way around this? This is really frustrating.

+3
source share
2 answers

I found him. Thanks for your reply.

static void StartOSK()
{
  string windir = Environment.GetEnvironmentVariable("WINDIR");
  string osk = null;

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "sysnative"), "osk.exe");
    if (!File.Exists(osk))
    {
      osk = null;
    }
  }

  if (osk == null)
  {
    osk = Path.Combine(Path.Combine(windir, "system32"), "osk.exe");
    if (!File.Exists(osk))
    {
      osk = null;
    }
  }

  if (osk == null)
  {
    osk = "osk.exe";
  }

  Process.Start(osk);
}
+3

PInvoking ShellExecuteEx() CreateProcess().

0

Source: https://habr.com/ru/post/1748413/


All Articles