Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatically execute a program and send button commands?? 1

Status
Not open for further replies.

neuron07

IS-IT--Management
Nov 17, 2003
7
0
0
US
Hello,

What I need to do is make a program that will run a Windows application and then send button (keyboard) commands (which I specify in the code), to the Windows application, eliminating the need for the user to get involved at all.

An example:
I want the c++ program to run the Windows application 'install.exe'. After the c++ program executes the file, the Windows application pops up with a window that has a disclamer (textbox), an I Agree checkbox, an I Disagree checkbox, and a 'Next >' button at the bottom. I want the c++ program to send the button (keyboard) commands:
Tab (selects the textbox disclamer)
Tab (selects the 'I Agree' checkbox)
SpaceBar (puts a checkmark in the 'I Agree' checkbox)
Enter (defaults to hitting the 'Next >' button)

This is basically what I want to accomplish by making this program. Any tips or comments would be great, and I appreciate you taking your time to read this. Thank you.


P.S. I tried making this program in VisualBasic, but I had some issues.

Travis
 
If you want so much to send key events, I believe you can write them in keyboard buffer or port. Windows has such kind of program, it is OnScreenKeyboard. But as I see you want to use key messages in an unusual way, I'd say you go in wrong direction.

Ion Filipski
1c.bmp
 
You could try getting the HWND of the actual items you are trying to control, then you wouldnt need to bother with sending keyboard commands. You could automatically set the value of the checkbox to ticked, then click the button via code.



Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
Skute, OnScreenKeyboard knows nothing about window handles which exist in the system. The operation system decides itself how to generate where to send messages from the physical or virtual keyboard.

Ion Filipski
1c.bmp
 
I made a program in Visual Basic that did everything I needed it to. It found the HWND values, clicked the mouse, and everything was working fine. However, I ran into an unusual problem. There were 21 patches that I was trying to run, but when I ran into a certain patch (when 2 or 3 had been successfully completed), after it was done and it clicked finish, it would try to run the next program, and it wouldn't load. I would have to restart the computer before I could run the next patch.

The wierd part about it is, when I do them manually, without the program, it doesn't stop letting me run them. I can do all of the patches without it stopping and having to restart.

So I'm trying to do it in C++, hoping that it will work a little better. If any of you have tried to make a similar program or know someone that has, please let me know.

Thank you for your feedback, it is much appreciated.
 
You go in a wrong direction. No install program is created to do something importand without user intervention. Or you're trying to create a virus? If so, yo don't need an installer at all.

Ion Filipski
1c.bmp
 
You can use the keybd_event function to send keyboard commands. The following simulates pressing the tab key down and then releasing it.

// Simulate a key down
keybd_event( VK_TAB,
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 );


// Simulate a key release
keybd_event( VK_TAB,
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);

As far as launching the program, you can use WinExec os CreateProcess

UINT WinExec(
"C:\\Install.exe", // command line
SW_SHOW // window style
);


Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top