﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ProcessArchDetection
{
    class Program
    {
        [DllImport("kernel32.dll", SetLastError = true)]
        private static extern bool IsWow64Process(IntPtr hProcess, out bool isWow64Process);
        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern IntPtr OpenProcess(
            ProcessAccessFlags processAccess,
            bool bInheritHandle,
            int processId
        );
        public static IntPtr OpenProcess(Process proc, ProcessAccessFlags flags)
        {
            return OpenProcess(flags, false, proc.Id);
        }
        [Flags]
        public enum ProcessAccessFlags : uint
        {
            All = 0x001F0FFF,
            Terminate = 0x00000001,
            CreateThread = 0x00000002,
            VirtualMemoryOperation = 0x00000008,
            VirtualMemoryRead = 0x00000010,
            VirtualMemoryWrite = 0x00000020,
            DuplicateHandle = 0x00000040,
            CreateProcess = 0x000000080,
            SetQuota = 0x00000100,
            SetInformation = 0x00000200,
            QueryInformation = 0x00000400,
            QueryLimitedInformation = 0x00001000,
            Synchronize = 0x00100000
        }
        static void Main(string[] args)
        {
            Process[] localAll = Process.GetProcesses();
            foreach (Process checkProcArch in localAll)
            {
                IntPtr procHandle = OpenProcess(ProcessAccessFlags.All, false, checkProcArch.Id);
                IsWow64Process(procHandle, out bool isit64);
                Console.WriteLine("Name: " + checkProcArch.ProcessName);
                Console.WriteLine("Process ID: " + checkProcArch.Id);
                Console.WriteLine("Is it x86: " + isit64);
                Console.WriteLine("\n");
            }
        }
    }
}
