Exception occurs when getting ProcessName

  • Thread starter Thread starter Patriot
  • Start date Start date
P

Patriot

I am having this error quite often, but not every time.
I have looked around some of these forums and don't seem to find any
post with the similar problem. Could someone point out what could be
the problem?

Dim myProcesses() As Diagnostics.Process
Dim myProcess As Diagnostics.Process
Dim sProcName As String

myProcesses = Diagnostics.Process.GetProcesses

For Each myProcess In myProcesses
With myProcess
sProcName = .ProcessName 'Exception here.
console.writeline(sProcName)
End With
Next



System.ComponentModel.Win32Exception: Unable to enumerate the process
modules.
at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId)
at System.Diagnostics.Process.get_Modules()
at System.Diagnostics.Process.get_MainModule()
at System.Diagnostics.Process.get_ProcessName()
at Process_Controller.ProcessKiller.Main() in C:\My
Projects\VB.Net\WindowsUtils\Process Killer\ProcessKiller.vb:line 41
 
It is possible that processes are being started and/or stopped during
execution.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
Back
Top