Visual Basic 中的 SendKeys() 权限被拒绝错误

发布于 2024-08-22 05:09:15 字数 300 浏览 8 评论 0原文

我正在尝试使用 SendKeys() 命令通过我的 VB6 应用程序发送到另一个窗口。

我想要的是单击一个按钮,然后在应用程序向该窗口发送一些按键之前有 10 秒钟的时间转到另一个窗口。我把一切都整理好了,但由于某种原因,当我调用这样的东西时:

SendKeys ("A")

我收到此错误:

Run-time error '70':

Permission denied

有人知道解决这个问题的方法吗?谢谢。

I am trying to use the SendKeys() command to another window with my VB6 app.

What I wanted is to click a button, and then have 10 seconds to go to the other window before the app sends some keys to that window. I got everything sorted but for some reason when I call something like this:

SendKeys ("A")

I get this error:

Run-time error '70':

Permission denied

Does anyone know a way around this? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

话少心凉 2024-08-29 05:09:15

对于 Windows 7:
将 UAC 设置更改为从不通知。

对于 Windows 8 和 10:
将此方法添加到任何模块:

Public Sub Sendkeys(text as variant, Optional wait As Boolean = False)
   Dim WshShell As Object
   Set WshShell = CreateObject("wscript.shell")
   WshShell.Sendkeys cstr(text), wait
   Set WshShell = Nothing
End Sub 

它在 Windows 10 中对我来说工作得很好。

For Windows 7:
Change the UAC settings to never notify.

For Windows 8 and 10:
Add this method to any module:

Public Sub Sendkeys(text as variant, Optional wait As Boolean = False)
   Dim WshShell As Object
   Set WshShell = CreateObject("wscript.shell")
   WshShell.Sendkeys cstr(text), wait
   Set WshShell = Nothing
End Sub 

It's worked fine for me in windows 10.

眼眸里的那抹悲凉 2024-08-29 05:09:15

看看 Karl Peterson 在 Vista 下解决这个问题的方法:

SendInput

Take a look at what Karl Peterson worked up as a fix for this under Vista:

SendInput

陪你到最终 2024-08-29 05:09:15

VB6 SendKeys 的替代品是 WScript.Shell SendKeys,如下所示:

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "1{+}"

请参阅 MSDN 寻求帮助。

Replacement for VB6 SendKeys is WScript.Shell SendKeys, like this:

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "1{+}"

See MSDN for help.

羁〃客ぐ 2024-08-29 05:09:15

在公共模块中添加:

Public Sub Sendkeys(text$, Optional wait As Boolean = False)
    Dim WshShell As Object
    Set WshShell = CreateObject("wscript.shell")
    WshShell.Sendkeys text, wait
    Set WshShell = Nothing
End Sub

这将“覆盖”SendKeys 函数

In a public Module add:

Public Sub Sendkeys(text$, Optional wait As Boolean = False)
    Dim WshShell As Object
    Set WshShell = CreateObject("wscript.shell")
    WshShell.Sendkeys text, wait
    Set WshShell = Nothing
End Sub

This will "overwrite" SendKeys Function

极致的悲 2024-08-29 05:09:15

在 Windows 7 上:

  • 打开控制面板
  • 更改用户帐户控制设置
  • 更改为从不通知
  • 重新启动计算机

On Windows 7:

  • Open the Control Panel
  • Change user account control setting
  • Change to NEVER NOTIFY
  • Restart the computer
饮湿 2024-08-29 05:09:15

从应用程序中删除“msvbvm60.dll”文件

按照以下步骤

操作

  1. 右键单击应用程序 .Exe 文件并单击“属性”
  2. 点击“兼容性”选项卡
  3. 单击“以兼容模式运行此程序”并选择“Windows”
    XP SP2 来自它。
  4. 点击“以管理员身份运行此程序”
  5. 点击“应用”即可。
  6. 从应用程序文件夹中删除“msvbvm60.dll”。

一切都完成了,现在您的应用程序开始运行,没有任何错误(例如拒绝访问)

Delete "msvbvm60.dll" File From The Application

Follow The Following Step

  1. Right Click On The Application .Exe File And Click On Property
  2. Click On Compatibility Tab
  3. Click On Run This Program in Compatibility Mode And Chose Windows
    Xp SP2 From It.
  4. Click On Run This Program As Administrator
  5. Click On Apply Than Ok.
  6. Delete The "msvbvm60.dll" From The Application Folder.

All Done, Now Your Application Start Running Without Any Error Like Access Denied

梦初启 2024-08-29 05:09:15

问题与 vb6 IDE 和 Windows 桌面上下文菜单有关,您将按照此处所述进行操作:

http://www.vbforums.com/showthread.php?747425-SendKeys-and-Windows-8

主要参考在这里:

http://www.vbforums.com/showthread.php?745925-已解决-如何-触发桌面上下文菜单

the problem is about vb6 IDE and windows desktop context menu and you will do as described in here :

http://www.vbforums.com/showthread.php?747425-SendKeys-and-Windows-8

and main reference is here :

http://www.vbforums.com/showthread.php?745925-RESOLVED-How-to-trigger-the-desktop-context-menu

深府石板幽径 2024-08-29 05:09:15

您可以在

Public Sub SendKeyTab(CForm As Form)
On Error Resume Next
Dim G As Single
For G = 0 To CForm .Controls.Count - 1
    If CForm .Controls(G).TabIndex = CForm .ActiveControl.TabIndex + 1 Then CForm .Controls(G).SetFocus
Next
End Sub

每个表单级别的模块中使用此代码

If KeyCode

You can use this code in Module

Public Sub SendKeyTab(CForm As Form)
On Error Resume Next
Dim G As Single
For G = 0 To CForm .Controls.Count - 1
    If CForm .Controls(G).TabIndex = CForm .ActiveControl.TabIndex + 1 Then CForm .Controls(G).SetFocus
Next
End Sub

On Each Form Level

If KeyCode
陌上芳菲 2024-08-29 05:09:15

使用此 API:

Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

keybd_event keycode, 0, 0, 0  'KEY DOWN
keybd_event keycode, 0, KEYEVENTF_KEYUP, 0 'KEY UP

按键代码为 32(空格)、35(键端)、8(vbKeyBack)等时。

Use this API:

Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

and

keybd_event keycode, 0, 0, 0  'KEY DOWN
keybd_event keycode, 0, KEYEVENTF_KEYUP, 0 'KEY UP

when key code is 32 for space, 35 for keyend, 8 for vbKeyBack, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文