如何从 VB-6 遗留应用程序中启动屏幕键盘程序

How to start the On-screen keyboard program from within a VB-6 legacy application

我正尝试从 VB-6 应用程序中 Windows 10-32 或 Windows 10-64 位机器上 'shell osk.exe'。

过去我们只是简单地使用:

Private Sub Command1_Click()
Dim strTemp As String
Dim fso1 As New FileSystemObject
strTemp = fso1.GetSpecialFolder(SystemFolder) & "\osk.exe"

Dim lngReturn As Long
Let lngReturn = ShellExecute(Me.hwnd, "Open", strTemp, vbNullString, "C:\", SW_SHOWNORMAL)

lblReturn.Caption = CStr(lngReturn)

end sub

我们也使用了更简单的 'shell' 命令;都不起作用。

并且在过去这很好用。我们还可以从我们的程序中打开 NotePad、msPaint 和其他一些实用程序。我们使用工业触摸屏 PC,为方便起见,我们在 'settings' 页面上放置了一些按钮以快速访问这些类型的帮助程序。我不想等待程序,我们的代码有它自己的 'touchscreen keyboard'。当用户想要在我们的主应用程序之外执行某些工作时,他们只会使用 Windows OSK。

对于 Windows XP,所有这些程序都可以正常打开。现在 Windows 10,只有 OSK.exe 程序不会启动。查看 return 代码,错误 returned 是“2”- 未找到文件(我假设)。但是在 c:\windows\system32 文件夹中,文件 'osk.exe' 与 mspaint.exe 和 notepad.exe 一起存在。

是否有某些 Windows 设置对我的程序隐藏了真正的 osk.exe?

感谢您的任何建议。

在我的 64 位 Windows10 上,您的代码的行为与您所说的一样。看起来在 64 位 windows 上你必须禁用 WOW 64 重定向:

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Const SW_SHOWNORMAL = 1

Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal Enable As Boolean) As Boolean '// ****Add this****

Private Sub Command1_Click()
    Dim fso1 As New FileSystemObject
    Dim strTemp As String

    strTemp = fso1.GetSpecialFolder(SystemFolder) & "\osk.exe"

    Dim lngReturn As Long
    Wow64EnableWow64FsRedirection False '// ****Add this****
    Let lngReturn = ShellExecute(Me.hwnd, "open", strTemp, vbNullString, "C:\", SW_SHOWNORMAL)
    Wow64EnableWow64FsRedirection True '// ****Add this****
    lblReturn.Caption = CStr(lngReturn)
End Sub

此代码在 Windows 10 64 位上非常有效。还在 Windows 10 32 位上进行了测试...也在那里工作。