Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendKeys() permission denied error in Visual Basic

Tags:

vb6

sendkeys

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.

like image 205
Phox Avatar asked Feb 21 '10 22:02

Phox


4 Answers

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.

like image 115
Eduardo de Santana Avatar answered Oct 14 '22 04:10

Eduardo de Santana


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

SendInput

like image 44
Jim Mack Avatar answered Oct 14 '22 04:10

Jim Mack


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

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

See MSDN for help.

like image 6
Roman Plischke Avatar answered Oct 14 '22 04:10

Roman Plischke


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

like image 5
rubStackOverflow Avatar answered Oct 14 '22 02:10

rubStackOverflow