Hi, I want to know if there is a way to get the PID generated when the start method of a web application is called. I know I can see this number via task manager, but I want to know if there is a property or method that retrieve that information so I can work with it within an automation.
@IsaiAbrahamM There isn’t a straight-forward way to get this right from the adapter or control itself. The simplest way is to use the script below. You can pass in the StartPage property of your web adapter (Internet Explorer) and it will essentially look for all IE processes that contain that as part of their command line. This wouldn’t work if you left the StartPage blank or if you were using the StartMethod of MonitorAll though. There is likely a way to get this through some more complicated code from the adapter using Reflection, however this is the most understandable method I could find.
Incidentally, it would be easier to do with the Universal Web Adapter as we have access to the Window Handle from a web page and can use that to get the PID (again through code, but more directly). We could write a script to translate the window handle to its Process ID that would grab that info relatively easily.
To use this, you must add a reference in your project to System.Management and also add a “using” statement for it in your script.
public string GetAdapterProcessID(string startPage)
{
string result = string.Empty;
ManagementClass mngmtClass = new ManagementClass(“Win32_Process”);
foreach (ManagementObject o in mngmtClass.GetInstances())
{
if (o[“Name”].Equals(“iexplore.exe”) && o[“CommandLine”].ToString().ToUpper().Contains(startPage.ToUpper()))
{
result = o[“ProcessId”].ToString();
}
}
return result;
}