.NET 的 Process.Modules 在内部使用函数 EnumProcessModules来自 PSAPI.dll.此功能存在无法运行的已知问题跨越 32/64 位进程边界.因此枚举另一个64 位进程从 32 位进程或反之亦然不起作用正确.解决方案似乎是使用 EnumProcessModulesEx 函数,(必须通过 P/Invoke 调用),但此函数仅在更高版本的 Windows 上可用.我们通过添加解决了这个问题一个名为 EnumProcessModulesEx 到 PSAPI.dll 的新函数(http://msdn2.microsoft.com/en-us/library/ms682633.aspx),但我们在这种情况下目前无法使用它:它仅适用于 Windows Vista 或 Windows Server 2008目前 .NET 2.0 Framework 没有服务包或修补程序来让 Process.Modules 使用这个新的 APII have been researching this issue pretty extensively and cannot seem to find an answer.I know that the Only part of a ReadProcessMemory or WriteProcessMemory request was completed exception is thrown when a 32-bit process tries to access a 64-bit process and the same for a 64-bit modifying a 32-bit process. The solution to that issue is to change the Platform Target to 'Any CPU'. I have tried this and unfortunately this does not solve my issue. The next block of code is what keeps throwing the exception. The program that runs this code is used to open up applications on remote computers and keeps a list of all the processes that the program itself opened so that I don't have to loop through all the processes. Process processToRemove = null;lock (_runningProcesses){ foreach (Process p in _runningProcesses) { foreach (ProcessModule module in p.Modules) { string[] strs = text.Split('\'); if (module.ModuleName.Equals(strs[strs.Length - 1])) { processToRemove = p; break; } } if (processToRemove != null) { break; } } if (processToRemove != null) { processToRemove.Kill(); _runningProcesses.Remove(processToRemove); }}These processes can and most likely will be 32-bit and 64-bit, mixed together.Is there anything I am doing that I shouldn't be doing, or is there just a better way to do all of this? 解决方案 As detailed in the comments of the MSDN page for Process.Modules and this thread there is a known issue in Process.Modules when enumerating 32 bit processes from a 64 bit process and visa-versa: Internally .NET's Process.Modules is using function EnumProcessModules from PSAPI.dll. This function has a known issue that it cannot work across 32/64 bit process boundary. Therefore enumerating another 64-bit process from 32-bit process or vice versa doesn't work correctly.The solution seems to be to use the EnumProcessModulesEx function, (which must be called via P/Invoke), however this function is only available on later versions of Windows. We fixed this issue by adding a new function called EnumProcessModulesEx to PSAPI.dll (http://msdn2.microsoft.com/en-us/library/ms682633.aspx), but we currently cannot use it in this case: it only works on Windows Vista or Windows Server 2008 currently .NET 2.0 Framework don't have a service pack or hotfix to make Process.Modules use this new API 这篇关于C# 在 Process.Kill() 期间仅完成部分 ReadProcessMemory 或 WriteProcessMemory 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 11:16