开发者

c# ListView populated with Current Processes Informations: PID/Process Name/Path error when not compiled for x64

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);
    p开发者_如何学编程rocessiListView.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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜