Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System.Windows.Forms.SendKeys

Posted on 2003-10-26
3
Medium Priority
?
1,239 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
[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 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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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