By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

What causes this try statement to go to catch?

P: 1
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 :
Expand|Select|Wrap|Line Numbers
  1.         Dim example as integer
  2.         Dim file2 As String
  3.         For Each p As Process In Process.GetProcesses
  4.             Try
  5.                 file2 = p.Modules(0).FileName
  6.             Catch ex2 As System.ComponentModel.Win32Exception
  7.                 file2 = "n/a"
  8.             End Try
  9.             If file2 = "C:\example.exe" Then
  10.                 example += 1
  11.             End If
  12.         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.exe" for example, that could cause a problem.
Jul 20 '12 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 100+
P: 465
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
Jul 20 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.