0

im still a bit new on c#, but ive got an minor issue where im trying to look for an module in a process, in order to filter it out in a list of processes..example, if i get a list of chrome processes, and want to filter out the ones that currently running flash player.. here is my sample code:

  Process[] myProcess = null;


        foreach (Process localAll in Process.GetProcesses())
        {
            try
            {
                if (localAll.ProcessName.Contains(processName))
                {

                    myProcess = Process.GetProcessesByName(localAll.ProcessName);

                }
            }
            catch { }
        }
        Process[] processList;



        if (myProcess.Any())

        {
            if (moduleName != null)

            {

                processList = myProcess
              .Where(process => process.Modules.OfType<ProcessModule>()
                .Any(module => module.ModuleName.Contains(moduleName))).ToArray();
                }
            else
            {
                processList = myProcess;
            }
            if (!processList.Any())
            {
                return;
            }

as im still new , i might still have some more errors to fix, but my main issue atm is :"A 32 bit processes cannot access modules of a 64 bit process" while im running a test app and entered the required info. regards ==edit

exception thrown:

System.ComponentModel.Win32Exception occurred HResult=0x80004005 Message=A 32 bit processes cannot access modules of a 64 bit process. Source=System StackTrace: at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, >Boolean firstModuleOnly) at System.Diagnostics.ProcessManager.GetModuleInfos(Int32 processId) at System.Diagnostics.Process.get_Modules() at ModuleTester.ProcessBox2.<>c__DisplayClass23_0.<.ctor>b__0(Process >process) in C:\Users\Ludwig\Desktop\ModuleTester - Copy\ModuleTester\ProcessBox2.cs:line 63 at System.Linq.Enumerable.WhereArrayIterator1.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at ModuleTester.ProcessBox2..ctor(String processName, String moduleName, >String testAob, UInt32 PiDd) in C:\Users\Ludwig\Desktop\ModuleTester - >Copy\ModuleTester\ProcessBox2.cs:line 62 at ModuleTester.Program.MProces(String process, String aob, String >module, UInt32 ppid, String t_aob) in C:\Users\Ludwig\Desktop\ModuleTester - >Copy\ModuleTester\Program.cs:line 35 at ModuleTester.Program.Main(String[] args) in C:\Users\Ludwig\Desktop>\ModuleTester - Copy\ModuleTester\Program.cs:line 27

Ludwig
  • 151
  • 5
  • 20
  • What happens with the code? Does it throw an exception? Does it gives you an empty result? - Which one is the 32 bits proccess, is it C#? Why can't you just make it 64 bits? – Theraot May 27 '17 at 18:50
  • 2
    Project > Properties > Build tab, untick the "Prefer 32-bit" checkbox. You don't prefer it. – Hans Passant May 27 '17 at 18:52
  • Are you combining more than one project. It looks like the 32 bit project is trying to execute code that was compiled in 64 bit mode. – jdweng May 27 '17 at 20:29
  • See also https://stackoverflow.com/questions/17892623/how-can-i-run-an-any-cpu-net-executable-programmatically-in-either-32-bit-or-64 and https://stackoverflow.com/questions/9501771/how-to-avoid-a-win32-exception-when-accessing-process-mainmodule-filename-in-c – Peter Duniho May 27 '17 at 20:53

0 Answers0