What causes this try statement to go to catch?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • killmerat
    New Member
    • Jul 2012
    • 1

    What causes this try statement to go to catch?

    Sorry if the question wasn't clear, it'd be too much to type if it were.

    I found some code a few days ago that reads the executable path of every process but returns an error when trying to get certain processes. I didn't make all of this code :
    Code:
            Dim example as integer
            Dim file2 As String
            For Each p As Process In Process.GetProcesses
                Try
                    file2 = p.Modules(0).FileName
                Catch ex2 As System.ComponentModel.Win32Exception
                    file2 = "n/a"
                End Try
                If file2 = "C:\example.exe" Then
                    example += 1
                End If
            Next
    I need to know exactly what causes it to return "n/a" because if I were to make present to me the information from, for example, a messagebox, some processes will return "n/a" and I need it to not do that or figure out another way of grabbing the executable paths.

    I don't want just the filename, anyone can bypass that and if it has the same name as "explorer.e xe" for example, that could cause a problem.
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    In your catch statement add MessageBox.Show (ex2.Message) and that will give you the actual error. I presume it's a permission issue and this will let you know

    Comment

    Working...