How to get Main process child window / or process name

Hi Team
I am working on a project,

I need to check how many processes or windows are open in the main process.
I am able to fetch the main Process name, But I want to check the subprocess name as well.
Can you please guide me?

@JSR_Techno_Talk_s

Try importing system.Diagnostics in the imports panel and use as below in invoke code


Dim mainProcesses() As Process = Process.GetProcessesByName(mainProcessName)

If mainProcesses.Length > 0 Then
        Dim mainProcessId As Integer = mainProcesses(0).Id

        Dim subProcesses() As Process = Process.GetProcesses().Where(Function(p) p.ParentProcessId = mainProcessId).ToArray()

        For Each subProcess As Process In subProcesses
            Console.WriteLine("Process Name: " & subProcess.ProcessName)
            Console.WriteLine("Process ID: " & subProcess.Id)
            Console.WriteLine("-------------------------------------------------")
        Next
    Else
        Console.WriteLine("Main process not found.")
    End If

Cheers

Getting Error

@Anil_G : Any suggestion ?

@JSR_Techno_Talk_s

Please try this…I just saw parent was not working…compiled one mroe code


Dim mainProcesses() As Process = Process.GetProcessesByName("MainProcessName")

    If mainProcesses.Length > 0 Then
        Dim mainProcessId As Integer = mainProcesses(0).Id

		Dim searcher As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Process")
        Dim processesCollection As System.Management.ManagementObjectCollection = searcher.Get()

        For Each process As System.Management.ManagementObject In processesCollection
            Dim processId As Integer = Convert.ToInt32(process("ProcessId"))
            Dim parentProcessId As Integer = Convert.ToInt32(process("ParentProcessId"))

            If parentProcessId = mainProcessId Then
                Console.WriteLine("Process Name: " + process("Name").ToString)
                Console.WriteLine("Process ID: " + processId.ToString)
                Console.WriteLine("-------------------------------------------------")
            End If
        Next
    Else
        Console.WriteLine("Main process not found.")
    End If

image

cheers

Thanks @Anil_G

Its Giving me only main process name . Parent process name only

Dim mainProcesses() As Process = Process.GetProcessesByName(MainProcess)
Console.WriteLine("Main Process Name: " + MainProcess.ToString)
If mainProcesses.Length > 0 Then
Dim mainProcessId As Integer = mainProcesses(0).Id
Console.WriteLine("Main Process ID: " + mainProcessId.ToString)