CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    How do I send a "command" to a run application? Or check if a program is running?

    Let's say I want to send a text message automaticly to a program that's running (which one should be defined by selecting a directory)

    Or just if I have "cmd" open. I should be able to start a command line, like "rename *.jpg *.bmp" or something alike, and if the "cmd" isn't open, it should tell the user that the program isn't loaded. Is there any API command for this or anyone with a good code to check over?

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: How do I send a "command" to a run application? Or check if a program is running?

    Is the program to which you want to send commands written by you ? Because the program itself needs to be able to accept commands from outside. Otherwisw you could not 'send' commands to an application.
    For example excel. word, outlook can be handled by VB programs a lot of others can't.

    I Think there is some more information needed to answer your question.

    Jonny Poet
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: How do I send a "command" to a run application? Or check if a program is running?

    It's suppose to be a "quick" tool for a Game, sort of like a trainer or something alike, but not like, but the same usage only that you just have to press a certain key and it executes it in the Game.

    Do you understand?

    Its sort of the same purpose that I need it by.
    But to know if it works to send a command to the Game, I need to test it right? Is there any method that you or anyone else know of?

  4. #4
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: How do I send a "command" to a run application? Or check if a program is running?

    Wouldn't it sort of work, IF, let's say this:

    The game is running in a "Window-mode" but the Window itself ain't focused, the program that I'm trying to create is.

    BUT!

    When you press a certain button, it should first set the Focus on the window of the game.

    AND THEN!

    Use "SendKeys" or anything that works as if you've pressed a button and entered a line of command.

    In many multiplayer games you press "Enter" to speak to other people.

    Let's say if the tool should
    1. "Focus the window"
    2. Send a signal like if you've pressed the "Enter" key yourself
    3. Paste a line that should be entered
    4. Send a signal again that should look like you've pressed Enter.


    IS that a method, but how do I do it?

  5. #5
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: How do I send a "command" to a run application? Or check if a program is running?

    Quote Originally Posted by Deukalion
    ...
    Use "SendKeys" or anything that works as if you've pressed a button and entered a line of command.
    I have seen such programs but I'm sorry I dont know how they do that.


    jonny Poet
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  6. #6
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: How do I send a "command" to a run application? Or check if a program is running?

    Do you know how I set the Focus on a "open program"? then?

  7. #7
    Join Date
    Dec 2002
    Location
    London, UK
    Posts
    1,569

    Re: How do I send a "command" to a run application? Or check if a program is running?

    Well, to achieve this you don't need to "focus" the window exactly... you can actually just get the windows handle (see below) and then use send keys with it.

    To get the handle you can use the FindWindow API call. There is also a FindWindowLike function which I have posted here a couple of times, have a search for it. (I didn't write it... it came from M$, but I improved it abit).

    To send the message you use the SendMessage API.

    e.g. This code I wrote a while back... It was made to start a self extracted EXE made with winrar, and then automatically fill in the install location and click the install button.
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As Long, _
         ByVal Msg As Long, _
         ByVal wParam As Long, _
         ByVal lParam As Long) As Long
    ...
    ...
    ...
        'Start the install process
        Shell ("WinampToolbarCompressed.exe")
        'Get the window handle
        r = FindWindowLike(hWnds(), 0, "WinRAR self-extracting archive", "*", Null)
        hWndOfMainWindow = hWnds(1)
        
        'Get the text area of the combo box window
        r = FindWindowLike(hWnds(), hWndOfMainWindow, "", "ComboBox", Null)
        r = FindWindowLike(hWnds(), hWnds(1), "", "Edit", Null)
        
        If r = 1 Then
            'Sendkeys to the window handle
            'Delete the current text
            For i = 1 To 1000
                r = SendMessage(hWnds(1), WM_KEYDOWN, 46, 0)
            Next
            
            'Enter the new text
            For i = 1 To Len(lblInstallTo.Caption)
                r = SendMessage(hWnds(1), WM_CHAR, Asc(Mid(lblInstallTo.Caption, i, 1)), 0)
            Next i
        End If
        
        'Find and press the Install button
        r = FindWindowLike(hWnds(), hWndOfMainWindow, "Install", "Button", Null)
        r = SendMessage(hWnds(1), WM_LBUTTONDOWN, 1, 655370)
        r = SendMessage(hWnds(1), WM_LBUTTONUP, 0, 655370)
    ...
    ...
    ...
    Mike

  8. #8
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: How do I send a "command" to a run application? Or check if a program is running?

    Where can I get info on what "API" calls that are avaible?
    I've never heard of the "API" calls that you was talking about.

    Isn't there an OCX with all of the API's in one? Just a bit simpler.

    Cause I'm not that awesome in VB so I don't really now how to get some "outer" functions to work with VB.

  9. #9
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: How do I send a "command" to a run application? Or check if a program is running?

    I mean, there must be some kind of source on where you can find the knowledge of the "API"s that are avaible, right? Or anything alike it. Cause how can I know what "functions" are bound to a certain DLL that I have?

    Say I have a program that uses its function from a dll, and its a freeware program that I can use myself for my app, how can I get the information that I need that is stored within the DLL file? On what functions that can be used by it? This is gone a bit off topic now but..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured