I’m using this code to get a list of current proccess.
For Each Proc As Process In ProcessList
Dim ProcessList As List(Of Process) = Process.GetProcesses.ToList
Dim Name As String = Proc.ProcessName
Dim Path As String = Proc.MainModule.FileName
Dim Icon As System.Drawing.Image = System.Drawing.Icon.ExtractAssociatedIcon(Path).ToBitmap
next
but I get an error on Dim Path As String = Proc.MainModule.FileName)
which I think is because I’m using 64bit OS.
Thanks in advance
CodePudding user response:
First of all you have ProcessList declared in your loop. I assume that was a paste error.
The problem is that you can't access all the processes like that. You will need to add a try catch.
Dim ProcessList As List(Of Process) = Process.GetProcesses.ToList
For Each Proc As Process In ProcessList
Dim Name As String = Proc.ProcessName
Dim v = Environment.Is64BitProcess
Try
Dim Path As String = Proc.MainModule.FileName
Dim Icon As System.Drawing.Image = System.Drawing.Icon.ExtractAssociatedIcon(Path).ToBitmap
Catch ex As Exception
Debug.WriteLine("Can't Access File Name: " ex.Message ", Process Name: " Name)
End Try
Next
See here for more details.
How to avoid a Win32 exception when accessing Process.MainModule.FileName in C#?