0

I'm running a Windows 7 x64 machine when I do not compile for x64 I get an exception and my ListView just get populated with the first two non x64 processes.

That is I cannot access MainModule Property of a 64 bit process to get it's full path.

foreach(Process p in listaProcessi) 
{
    tempItem = new ListViewItem(p.Id.ToString());
    tempItem.SubItems.Add(p.ProcessName);
    tempItem.SubItems.Add(p.MainModule.FileName);
    processiListView.Items.Add(tempItem);
}

I still can make it work compiling for x64 but suppose I want to compile just for x86, how do I avoid getting the excpetion ?

1) Is there any other way to discover those processes path ?

2) I could write a line like "You cannot get x64 Process path from x86 App", but still I don't have to run into the exception. How do I prevent this ? Can I check the process for a particular info so I can replace the text and avoid accessing MainModule ?

Thanks.

Marco
  • 56,740
  • 14
  • 129
  • 152
Relok
  • 301
  • 4
  • 14
  • 1
    what is the exception stack trace and details? Try to build for AnyCPU, not x86 and not x64... how does it work? – Davide Piras Sep 09 '11 at 16:51
  • 1
    Are you getting the "System.ComponentModel.Win32Exception: Unable to enumerate the process modules"? This is usually true for processes running under "System" credentials irrespective of x86 and x64. – Kash Sep 09 '11 at 17:04
  • By default it Runs an Active Debug (Config) Platform: Active(x86) Platform target: x86 This generates: Exception:Thrown: "A 32 bit processes cannot access modules of a 64 bit process." (System.ComponentModel.Win32Exception) A System.ComponentModel.Win32Exception was thrown: "A 32 bit processes cannot access modules of a 64 bit process." By changing to Platform target: x64 or AnyCPU I don't get any exception. So selecting AnyCPU should be fine because If I run it on my System it will run as x64 and so it can access x64 Modules if run on x86 machine should work because there is no x64 process. – Relok Sep 09 '11 at 17:24
  • Anyway are there any other methods to get a process file path ? Just for curiosity. :) – Relok Sep 09 '11 at 17:28
  • You need to use the WMI. Please see my answer [here](http://stackoverflow.com/a/9738145/385995). – Mike Fuchs Mar 16 '12 at 13:59

1 Answers1

0

A 32 bit processes cannot access modules of a 64 bit process.

So it must be compiled for AnyCpu to be fully working in both x86 and x64 environments.

Relok
  • 301
  • 4
  • 14