0

Is there a way i can print all the applications that run on my computer? I would like to after that handle one of them and find the button and click on it. I would like to simulate a click button on a specific window. Firstly I would like to print all the running applications and get a handle over them.Can someone give me a some code?

1 Answer 1

1
Use System.Management;
//Return all processes
public static string ListAllProcesses()
{
    StringBuilder sbAllProcess = new StringBuilder();
    // list out all processes and write them into a stringbuilder
    ManagementClass MgmtClass = new ManagementClass("Win32_Process");

    foreach (ManagementObject mobject in MgmtClass.GetInstances())
    {
        sbAllProcess .Append("Name:\t" + mobject ["Name"] + Environment.NewLine);
        sbAllProcess .Append("ID:\t" + mobject ["ProcessId"] + Environment.NewLine);
        sbAllProcess .Append(Environment.NewLine);
    }

    return sbAllProcess .ToString();
}
//Return all applications
public static string ListAllApplications()
{
    StringBuilder sbAllApplication = new StringBuilder();

    foreach (Process runningProcess in Process.GetProcesses("."))
    {
        try
        {
            if (runningProcess .MainWindowTitle.Length > 0)
            {
                sbAllApplication .Append("Window Title:\t" + runningProcess .MainWindowTitle.ToString()+ Environment.NewLine);
                sbAllApplication .Append("Process Name:\t" + runningProcess .ProcessName.ToString() + Environment.NewLine);
                sbAllApplication .Append("Window Handle:\t" + runningProcess .MainWindowHandle.ToString() + Environment.NewLine);
                sbAllApplication .Append("Memory Allocation:\t" + runningProcess .PrivateMemorySize64.ToString() + Environment.NewLine);
                sbAllApplication .Append(Environment.NewLine);
            }
        }
        catch { }
    }
    return sbAllApplication .ToString();
}
Sign up to request clarification or add additional context in comments.

3 Comments

Now you have a list of processes and application and you can write into a file and print it out.
how can i find the child window to a specific window?
Using pinvoke.net/default.aspx/user32/EnumChildWindows.html Enumchildwindows u will get to know handlers of child window of specific window.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.