daydr3am3r
daydr3am3r

Reputation: 61

Launch x64 Windows application in C# while the project is set to x86

I'm trying to launch the osk.exe and I keep getting "Could not start osk" message. The problem is that my project is set to x86 (i'm using a ms access database). If I switch to x64 or Any CPU everything works fine but the database will no longer work. 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 this also didn't work. Besides my application should run on both x86 and x64 machines. Is there any way to bypass this? It's really frustrating.

Upvotes: 3

Views: 2751

Answers (2)

daydr3am3r
daydr3am3r

Reputation: 61

I found it. Thanks for your answer.

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

Upvotes: 3

shoosh
shoosh

Reputation: 79013

You can try PInvoking ShellExecuteEx() or CreateProcess() directly.
Here's a link

Upvotes: 0

Related Questions