|
-
Dec 9th, 2013, 07:11 PM
#1
Thread Starter
Member
SendKeys brings up Cannot Hook Error
Hello. I've been tralling the interwebs for a few hours now, and there is this one piece of code that is preventing my entire application from being complete!
Essentially, my application waits until a set of variables are equal to what they should be then it sends keys to the currently active window.
The code I am using is
But, whenever my program gets to the stage of doing this, it comes up with a security error.
Code:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Security.SecurityException: Hook cannot be created.
at System.Windows.Forms.SendKeys.InstallHook()
at System.Windows.Forms.SendKeys.Send(String keys, Control control, Boolean wait)
at System.Windows.Forms.SendKeys.Send(String keys)
at WindowsApplication1.Form1.Timer1_Tick(Object sender, EventArgs e) in C:\Users\Darren Steels\Dropbox\CB\CB\Form1.vb:line 174
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The Zone of the assembly that failed was:
MyComputer
As I copy and paste, the application did start sending the Number 4 to chrome within this textbox!
Code:
4444444444444444444444
as expected, so why doesn't it work within this other application?
UAC is disabled on my machine, and I even right click the application and click run as administrator. Nothing.
I have installed .Net 1.1, 1.1SP1 and the SendKeys Hotfix, in hopes that it may possibly work, it didn't, I assume because my project is using .Net 4
I have looked at SendInput, but the code wasn't clear or wasn't for the version of VB I am using. I have looked at keybd_event, but can't find any code at all to do with that.
I just need something to use as an alternative to SendKeys that will send key presses to another application, no questions asked...
Any help much appreciated!
Thanks!
~ TheMeq ~
If I helped in anyway, please hit the star and send me some rep! Thanks
-
Dec 9th, 2013, 07:36 PM
#2
Re: SendKeys brings up Cannot Hook Error
I saw the article that you're referring to I believe(this one?), but you mentioned that you're developing your project using the 4.0 .Net Framework. So that really wouldn't apply for your project because that's applicable for projects targeting the 1.1 .Net Framework.
Now I've done a bit of research on this(Google baby!) and to be honest, I can't really find anything. A few things to try:
A) Be sure that you're running the program as administrator on a user account that is an administrator. I know you mentioned that you're running the program as administrator, but doing that on a user account that is an admin may make a difference
B) As slow as this may sound, wrap the SendKeys in a Try/Catch and post that exception will be thrown.
-
Dec 9th, 2013, 10:15 PM
#3
Re: SendKeys brings up Cannot Hook Error
Where is the SendKey call located? In a button click event, textbox lostfocus event, a sub/function?? Show all the relevant code.
-
Dec 10th, 2013, 02:41 AM
#4
Thread Starter
Member
Re: SendKeys brings up Cannot Hook Error
 Originally Posted by wes4dbt
Where is the SendKey call located? In a button click event, textbox lostfocus event, a sub/function?? Show all the relevant code.
All the relevant code is posted. If you read the error, you see it is triggered from a timer event. On tick, if a=b then send keys end if
~ TheMeq ~
If I helped in anyway, please hit the star and send me some rep! Thanks
-
Dec 10th, 2013, 05:32 AM
#5
Re: SendKeys brings up Cannot Hook Error
Did you put this in your app.config?
Code:
<configuration>
<appSettings>
<add key="SendKeys" value="SendInput"/>
</appSettings>
</configuration>
-
Dec 10th, 2013, 08:38 AM
#6
Thread Starter
Member
Re: SendKeys brings up Cannot Hook Error
I have added that piece of code and will try it tonight, can you explain exactly what this will do, I thought the issue was more to do with windows security more then my application. Thanks
~ TheMeq ~
If I helped in anyway, please hit the star and send me some rep! Thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|