简体   繁体   English

在项目设置为x86时,在C#中启动x64 Windows应用程序

[英]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. 我正在尝试启动osk.exe并且我一直收到“无法启动osk”消息。 The problem is that my project is set to x86 (i'm using a ms access database). 问题是我的项目设置为x86(我正在使用ms访问数据库)。 If I switch to x64 or Any CPU everything works fine but the database will no longer work. 如果我切换到x64或任何CPU一切正常,但数据库将不再工作。 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. 我也试过运行SysWOWW \\ osk,但这也行不通。 Besides my application should run on both x86 and x64 machines. 除了我的应用程序应该在x86和x64机器上运行。 Is there any way to bypass this? 有没有办法绕过这个? It's really frustrating. 真的很令人沮丧。

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

You can try PInvoking ShellExecuteEx() or CreateProcess() directly. 您可以直接尝试PInvoking ShellExecuteEx()CreateProcess()
Here's a link 这是一个链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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