How to get information from another running program?

Asked

Viewed 1,701 times

5

Updated

I thought my question would get lost and I honestly didn’t even see it reopened. But taking advantage that now there was a move to update on my app. It is being developed in C# and therefore for Windows (but I can change this by changing it to C++, but they are just plans).

Question

As specifications: I need a function/procedure/library/anything that makes it possible for me to capture information from another open executable. The idea is that when my app and an emulator (like ZSNES) are open, I can retrieve information from it, such as:

  • whether the window is focused or not,
  • which keys were pressed (with my application obviously blurred),
  • catch the window title since I know the process name,
  • and, if possible, find out which game is being played (some emulators log a log, others unfortunately do not).
  • Take a look at how the AHK does this because he has an inspector who shows a diversity of things about the running processes, in addition to serving naturally to automate and receive and inject events into these. Also, remember that with 64-bit Oses, you will most likely need a 64-bit process, because if it is 32, it will not access all the machine processes.

  • I found this program interesting! It will probably help me a lot. You ended up helping me twice because I remembered the word 'macro' and maybe it’s a little of what I need!

  • 5

    Hi, Gabriel, instead of seeking conflict, which is not cool when we are asking for free help from strangers, I suggest a read on Good Subjective, Bad Subjective (en). You say you’ve done a lot of research, so it’s nice to edit the question to show that and try to focus on the linked guide. Good luck!

  • But there was no reason even to close it, it is a clear question that seeks to know details of such a program. They probably didn’t even read it when I said that despite the research I didn’t get back. I’m not much to ask (you can see from my other OS profile, which I have more than 1 year bill). I’ve been programming for a long time, and I’ve never found a language that can do that. As you can see, I have received no reply so I do not understand how the complaint from you can be true. .

  • 3

    Hi Gabriel. I agree with you that "based on opinions" is a strange closing reason for this question. Don’t you want to open a discussion on the subject in [meta]? I believe that the question may very well be reopened if both parties argue. Just don’t go for the offense. Another thing, do not feel personally offended by the suspension of the question, it is not a "complaint" as you said, nor anything against you. It is only the opinion of five users of the site.

  • This information will get you through Windows API. It can be accessed from various languages.

  • 1

    @bfavaretto , in no way I disagree with the rules, I understand the reasons of the site. I am exposing to you that I do not seek opinions, I seek objective and definitive answers that can solve my problem. The rules are no problem, the problem is that you combat subjectivity with subjectivity. So far no one has presented a concrete problem. And I’m sorry I overreacted a little.

  • @Tony, could you tell me how?

  • What I’m saying is that taking the subject to the goal increases the chances of solving the problem, reopening the question (in case you don’t know, the goal is where we discuss the site). I even agree with you, but 5 people found something else and it would be good to discuss with them (I’m sure that most or all of these users attend the goal).

  • Ah yes, I understand, I will see how it preceded until the evening, probably I will do just that. Thank you!

  • 6

    I opened a question in Meta to discuss this.

  • @Gabriel You did not specify the OS in what this has to work.

  • @Vincent I updated the question with updated information.

Show 8 more comments

1 answer

1

This code below lists the processes being executed by the Operating System:

import java.io.*;

public class Teste {
  public static void main(String[] args) {
    try {
      Process p = Runtime.getRuntime().exec("ps ax"); // comando que vai pegar os processos

      BufferedReader resultado = new BufferedReader(new InputStreamReader(p.getInputStream()));

      //mostra os resultados obtidos pelo comando "ps ax"
      String s;
      while ((s = resultado.readLine()) != null)
        System.out.println(s);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

Link to a site with more in-depth discussion in other languages: Detection of Running Programs

  • This will only work on an OS type ' *Nix' (*BSD, OS X, Linux). Also not on the information about open windows, which is focused ...

  • ok... the more I provided was just part of the solution... the other part I indicated a website about a discussion about such a problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.