public static MODULEENTRY32[] GetRunningModulesOfProcess(int processId) { List <MODULEENTRY32> entries = new List <MODULEENTRY32>(); using (var h = ToolHelp.CreateToolhelp32Snapshot(ToolHelpFlags.TH32CS_SNAPMODULE, processId)) { if (h.IsInvalid) { var code = Marshal.GetLastWin32Error(); } MODULEENTRY32 entry = new MODULEENTRY32() { dwSize = (uint)Marshal.SizeOf(typeof(MODULEENTRY32)) }; var s = ToolHelp.Module32First(h, ref entry); if (!s) { var code = Marshal.GetLastWin32Error(); Console.WriteLine(code); } bool f = true; while (f) { var st = ToolHelp.Module32Next(h, ref entry); var code = Marshal.GetLastWin32Error(); if (code == 18) { f = false; } Console.WriteLine(entry.szExePath); } } return(entries.ToArray()); }