Hi,
I am facing a problem while accesing System.Diagnostics.Process.GetProcessesByName(processName.Trim).
I have a datatable which contains the list of process names. I iterate through the table and get the process name and pass it to the GetProcessesByName function.
I get an exception "Unable to enumerate the process modules". The exception occurs when multiple process of same processname is present. The code work fine when a single process running the system. Later i also get aan exception "Access Denied". The code snippet where the exception is thrown is below.
Help would be really appreciated. Thank You.
I am facing a problem while accesing System.Diagnostics.Process.GetProcessesByName(processName.Trim).
I have a datatable which contains the list of process names. I iterate through the table and get the process name and pass it to the GetProcessesByName function.
I get an exception "Unable to enumerate the process modules". The exception occurs when multiple process of same processname is present. The code work fine when a single process running the system. Later i also get aan exception "Access Denied". The code snippet where the exception is thrown is below.
VB.NET:
For Each drRow As DataRow In m_tbApplications.Rows
'Getting the exe name.
processName = GetApplicationExeName(UCase(drRow ("Name").ToString))
prc = System.Diagnostics.Process.GetProcessesByName(processName.Trim)
'If atleast one instance of the process is running.
If prc.Length > 0 Then
'Update the handle of the process window.
For Each pr As System.Diagnostics.Process In prc
'Fetching the right process to retrieve the handle.
'If the process id is the same as the one updated in m_tbApplications.
If String.Compare(pr.ProcessName, processName.ToString, True) = 0 _
AndAlso pr.Id = Convert.ToInt32(drRow("PID")) Then
If pr.MainWindowHandle.ToInt32 <> 0 Then
drRow("Handle") = pr.MainWindowHandle.ToInt32
End If
Exit For
End If
Next
End If
Next