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?
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.