?
Solved

windows dialog box, automation

Posted on 2003-03-07
9
Medium Priority
?
425 Views
Last Modified: 2012-06-27
This has to be a somewhat common issue.  I was wondering if anyone knows how to pass a string and emulate clicking an "OK" button from the command line?  Anything would be appreciated.

Thanks,

jay
0
Comment
Question by:jschneider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:TheBeaver
ID: 8092139
So you want to create an OK button in DOS?

1) Do a google on "int 10h"
This will explain everything you need to know to write characters on the screen to create the OK button and text.

2) Do a google on "int 33h"
This will explain everything you need to know about reading the current mouse position and button states. You then change the character where the mouse is currently pointing and voila! you have a mouse driven cursor.

3) If the mouse button is down and you are in your OK button....well, you do the do.

Hope that helps as a starter
0
 

Author Comment

by:jschneider
ID: 8092228
hmm... thanks TheBeaver, but Assembly programming is beyond me.  I guess my original question is not very clear, if I were to post it again it would say:

"Is there a way to pass from the command line to a windows dialog box a string and a mouse click action?"  

I am trying to automate through bat/shell scripting and one point I have to pass in a password and click OK to continue.  

Thanks again,

Jay
0
 
LVL 27

Expert Comment

by:Dabas
ID: 8093688
I do not see there being a problem.

You can capture the parameter in the command line with the Command function

So lets assume your program's exe file is MyProgram.exe
You want to call it like this:

MyProgram password OK

You have a form named Form1 that has:

a text box named Text1
a CommandButton named cmdOK
a CommandButton named cmdCancel
a CommandButton named cmdYes
a CommandButton named cmdNo

Then your code would look something like:

Private Sub Form_Load()
    Dim Pos As Integer
    Dim strButton As String
   
    Pos = InStr(Command, " ") 'Look for space
    Text1 = Left(Command, Pos - 1) 'Password is before the space. Fill TextBox with its contents

    strButton = Mid(Command, Pos + 1)'Button to click is after the space
   
    Select Case Trim(strButton)'Check which button to click on
    Case "OK"
        cmdOK = True 'Setting a button to true is the same as clicking on it
    Case "Yes"
        cmdYes = True
    Case "No"
        cmdNo = True
    Case Else
        cmdCancel = True
    End Select
End Sub


---------
Dabas
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:Dabas
ID: 8093694
Above code is in Visual Basic, but can easily be adapted to any other Windows language.

Dabas
0
 
LVL 9

Expert Comment

by:Joeisanerd
ID: 8095899
My guess is that you are looking to automate running some other program that you didn't write such as defrag for windows 2000 and you don't want users to be admins so you want to launch the defrag program with the runas and type in the admin password and click ok via code. If I am at all close let me know.

In order to do this you need to know the executable name or window class name so you can call FindWindow and get a handle to the window, then you can PostMessage to the window to post text to the text part and PostMessage the Ok clicking.Finding the code for this is the hard part.
0
 
LVL 27

Expert Comment

by:Dabas
ID: 8095915
If that is the case, and the program is a windows program you can probably still solve the problem using the SendKeys command (VB, probably similar in other MS languages)
0
 
LVL 9

Accepted Solution

by:
Joeisanerd earned 750 total points
ID: 8095918
My guess is that you are looking to automate running some other program that you didn't write such as defrag for windows 2000 and you don't want users to be admins so you want to launch the defrag program with the runas and type in the admin password and click ok via code. If I am at all close let me know.

In order to do this you need to know the executable name or window class name so you can call FindWindow and get a handle to the window, then you can PostMessage to the window to post text to the text part and PostMessage the Ok clicking.Finding the code for this is the hard part.
0
 

Author Comment

by:jschneider
ID: 8104266
Joeisanerd.

   Thank you and Yes, I am trying to automate code signing an exectuable during the build process.  The application that is prompting for a password (and provides no way on the command line to pass it in) is signdoce.exe.    Would you happen to have any code samples?  Otherwise, I think that I have something to work with.

Thank you,

Jay
0
 
LVL 9

Expert Comment

by:Joeisanerd
ID: 8104974
The best resource is Microsoft's msdn http://msdn.microsoft.com

If you call FindWindow(NULL,"Untitled - Notepad");
when a new notepad document is open then it will return a HWND handle to the window. At that point use PostMessage to post the right messages to the program. I haven't done much with this, but I have been able to tell that window to close by PostMessage(windowhandle,WM_CLOSE);

You just need to search the web for the proper post message.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Make the most of your online learning experience.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question