How can I get the window class name of a certain process? I want to achieve this in c#.
I\'ve tried the process class in c# but I can only get the window name of the
You can also use the windows ui automation framework to achieve this without getting into pinvoke.
int pidToSearch = 316;
//Init a condition indicating that you want to search by process id.
var condition = new PropertyCondition(AutomationElementIdentifiers.ProcessIdProperty,
pidToSearch);
//Find the automation element matching the criteria
AutomationElement element = AutomationElement.RootElement.FindFirst(
TreeScope.Children, condition);
//get the classname
var className = element.Current.ClassName;
I assume you mean you want to get the class name of the main window of a process.
To do this, you will need to get the handle to the main window using the MainWindowHandle
of your Process
object, and then use the following interop method to obtain the class name:
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
see pinvoke.net for sample code and MSDN for details on the function.