【发布时间】:2021-05-09 00:39:52
【问题描述】:
在研究如何使 osk 可见时,我找到了下面的代码,创建了一个新的解决方案,添加了 2 个按钮,粘贴到代码中,它运行良好。 当我将它添加到我一直在研究的解决方案中时,什么也没发生:
Public Class Form1
Declare Function Wow64DisableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
Declare Function Wow64EnableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
Private osk As String = "C:\Windows\System32\osk.exe"
Private pOSK As Process = Nothing
Private Sub Keyboard_Show()
'An instance is running
For Each pkiller As Process In Process.GetProcesses
If String.Compare(pkiller.ProcessName, "osk", True) = 0 Then pOSK = pkiller
Next
'If no instance of OSK is running than create one depending on 32/64 bit
For Each pkiller As Process In Process.GetProcesses
If Not (String.Compare(pkiller.ProcessName, "osk", True) = 0) And (pOSK Is Nothing) Then
Dim old As Long
If Environment.Is64BitOperatingSystem Then ' returns true
'64 Bit
If Wow64DisableWow64FsRedirection(old) Then ' returns false
pOSK = Process.Start(osk)
Wow64EnableWow64FsRedirection(old)
End If
Else
'32 Bit
pOSK = Process.Start(osk)
End If
Exit For
End If
Next
End Sub
Public Sub Keyboard_Show()
'An instance is running
For Each pkiller As Process In Process.GetProcesses
If String.Compare(pkiller.ProcessName, "osk", True) = 0 Then pOSK = pkiller
Next
'If no instance of OSK is running than create one depending on 32/64 bit
For Each pkiller As Process In Process.GetProcesses
If Not (String.Compare(pkiller.ProcessName, "osk", True) = 0) And (pOSK Is Nothing) Then
Dim old As Long
If Environment.Is64BitOperatingSystem Then
'64 Bit
If Wow64DisableWow64FsRedirection(old) Then
pOSK = Process.Start(osk)
Wow64EnableWow64FsRedirection(old)
End If
Else
'32 Bit
pOSK = Process.Start(osk)
End If
Exit For
End If
Next
End Sub
在我的实际项目上运行时,
If Environment.Is64BitOperatingSystem Then 返回 True,但 If Wow64DisableWow64FsRedirection(old) Then 返回 False
出于故障排除的目的,我尝试避免使用整个子例程,只使用 Process.Start("c:\windows\system32\osk.exe") 引发异常:System.ComponentModel.Win32Exception: 'The requested operation requires elevation.'
想法?任何帮助将不胜感激!
【问题讨论】: