Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

System.Windows.Forms.SendKeys

Posted on 2003-10-26
3
Medium Priority
?
1,250 Views
Last Modified: 2007-12-19
hi,
   Iam having a small problem in using the System.Windows.Forms.SendKeys API to send input to an active appication. I have an exe file for adding two numbers. I have to give input to that and get the result. My code ( which i have given below) works sometime and does not work someother time. It gives and unhandled exception error. can anyone tell me why?
 
   Dim myProcess As Process = New Process()
   myProcess.StartInfo.FileName = "Addition.exe"
   myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
   myProcess.EnableRaisingEvents = True
   myProcess.Start()
    Try
         If myProcess.Responding Then
           System.Windows.Forms.SendKeys.SendWait("2")
           System.Windows.Forms.SendKeys.SendWait("{ENTER}")
           System.Windows.Forms.SendKeys.SendWait("3")
           System.Windows.Forms.SendKeys.SendWait("{ENTER}")
           System.Windows.Forms.SendKeys.Send("{ENTER}")
           System.Windows.Forms.SendKeys.Flush()
         Else
            myProcess.Kill()
        End If

-sendhil

0
Comment
Question by:sendhil_an
3 Comments
 
LVL 4

Accepted Solution

by:
brother7 earned 200 total points
ID: 9624332
Lemme see if I understand this correctly...
1- The result is received back after the 2nd {ENTER}
2- The 3rd {ENTER}'s purpose is to try to end the process normally, ie in response to "Press any key to continue"

I would try the following:
   Add myProcess.CloseMainWindow() as the last statement of the If block, before the Else block.

Do you know the type of Exception that's occurring?
Add a Catch block, such as:
   Catch exceptionParameter as Exception
      MessageBox.Show(exceptionParameter.Message, "Caught Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
   End Try

Hope that helps some.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10224382
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: brother7 {http:#9624332}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

926 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