locked
to run an exe programmatically in C# RRS feed

  • Question

  • Hi ,

    Can someone please help me out in getting this milestone.

    Scenario is :

    I have an exe file on my machine. this exe file is having one windows form containig two text box and one button .

    need to run that exe programmatically in C#, passing input values to those textbox and has to fire that click event of that button.

    has to get the response of button click

    Thanks in Advance.

    Thursday, May 26, 2011 9:35 PM

Answers

  • It is like a automation job.

    For executing a application, you just can use Process.Start method as sharon mentioned.

    You will need a handler, then you can send message to window and control them in your code.

    Then you will need FindWindow funtion to find the Window and window handler.

    And then use SendMessage function to send string data or a click event message to window.

    I think you need some p/invoke knowledge to help you know how to call those windows API in .net code:

    http://msdn.microsoft.com/en-us/magazine/cc164123.aspx

    http://msdn.microsoft.com/en-us/library/aa288468(v=VS.71).aspx

    You also can ref this thread:

    http://stackoverflow.com/questions/1100605/settext-of-textbox-in-external-app-win32-api

    http://support.microsoft.com/kb/186271

     

    Or you can consider using the Microsoft UI Automation API, which would be helpful to you, but we have no enough experience on this aspect technical, maybe need you study this knowledge yourself with samples provided.

    http://www.codeproject.com/KB/WPF/WPFUIAutomation.aspx

     

    I suggest you to use the first option, using the windows API send messages to window directly, it is simpler and more intuitive in my mind.

    And the second technical seems for the WPF application.

     

    For such aspect technical discussions, I think the windows dev related forum is the better option:

    http://social.msdn.microsoft.com/Forums/en-US/windowsaccessibilityandautomation/threads

    So, for more this aspect question, please ask them in that forum.

     

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, May 27, 2011 8:35 AM

All replies

  • try

    Process.Start("Application.exe");

    • Proposed as answer by cnsuman Friday, May 27, 2011 4:04 AM
    Friday, May 27, 2011 4:01 AM
  • Hi ,

    Can someone please help me out in getting this milestone.

    Scenario is :

    I have an exe file on my machine. this exe file is having one windows form containig two text box and one button .

    need to run that exe programmatically in C#, passing input values to those textbox and has to fire that click event of that button.

    has to get the response of button click

    Thanks in Advance.

    Starting the exe is easy using the Special Folder enumeration and the process start.

    However, passing input to values in textboxes (if the program has no feature for that, which is normally the case) comes direct in the area of malicious code. It is protected so even if you do a hack, than it is better not to publish that in this Microsoft forum. 

     


    Success
    Cor
    Friday, May 27, 2011 6:15 AM
  • It is like a automation job.

    For executing a application, you just can use Process.Start method as sharon mentioned.

    You will need a handler, then you can send message to window and control them in your code.

    Then you will need FindWindow funtion to find the Window and window handler.

    And then use SendMessage function to send string data or a click event message to window.

    I think you need some p/invoke knowledge to help you know how to call those windows API in .net code:

    http://msdn.microsoft.com/en-us/magazine/cc164123.aspx

    http://msdn.microsoft.com/en-us/library/aa288468(v=VS.71).aspx

    You also can ref this thread:

    http://stackoverflow.com/questions/1100605/settext-of-textbox-in-external-app-win32-api

    http://support.microsoft.com/kb/186271

     

    Or you can consider using the Microsoft UI Automation API, which would be helpful to you, but we have no enough experience on this aspect technical, maybe need you study this knowledge yourself with samples provided.

    http://www.codeproject.com/KB/WPF/WPFUIAutomation.aspx

     

    I suggest you to use the first option, using the windows API send messages to window directly, it is simpler and more intuitive in my mind.

    And the second technical seems for the WPF application.

     

    For such aspect technical discussions, I think the windows dev related forum is the better option:

    http://social.msdn.microsoft.com/Forums/en-US/windowsaccessibilityandautomation/threads

    So, for more this aspect question, please ask them in that forum.

     

    Best wishes,


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, May 27, 2011 8:35 AM
  • Hi Rajesh Rajpoot,
    I am writing to check the status of the issue on your side. 
    What about this problem now? 
    Would you mind letting us know the result of the suggestions?
    Best wishes,

    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 30, 2011 6:58 AM