try { System.Diagnostics.Process[] HandleP = System.Diagnostics.Process.GetProcessesByName("ProcessByName.exe"); System.Diagnostics.ProcessModuleCollection modules = HandleP[0].Modules; foreach (System.Diagnostics.ProcessModule i in modules) { if (i.ModuleName == "ModuleNeeded") { ThisModule = i.BaseAddress.ToInt32(); } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); }
A first chance exception of type 'System.IndexOutOfRangeException' occurred in MyApp.exe An unhandled exception of type 'System.IndexOutOfRangeException' occurred in MyApp.exe Additional information: Index was outside the bounds of the array.
if (HandleP.Length == 1) {foreach (System.Diagnostics.ProcessModule i in modules) {....