Exception occurs when getting ProcessName

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
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top