[英]c# handle all desktop applications and simulate button click
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.