public static IntPtr OpenProcess(Native.ProcessAccessFlags dwDesiredAccess, uint dwProcessId)
        {
            var ret = Native.OpenProcess(dwDesiredAccess, false, dwProcessId);

            if (ret == IntPtr.Zero)
            {
                throw new Win32Exception(Native.GetLastError());
            }

            return(ret);
        }
示例#2
0
        /// <summary>
        /// Opens a process handle
        /// </summary>
        /// <param name="accessFlags">The access permissions for the handle</param>
        /// <exception cref="ProcessOpenException">Thrown if openprocess fails</exception>
        public void OpenProcess(Native.ProcessAccessFlags accessFlags)
        {
            _handle = Native.OpenProcess(accessFlags, false, AssociatedProcess.Id);
            if (_handle == IntPtr.Zero)
            {
                throw new ProcessOpenException();
            }

            // Process is always 32bit on 32bit os
            if (!Environment.Is64BitOperatingSystem)
            {
                _is64Bit = false;
                return;
            }

            // Check for wow64 process
            Native.IsWow64Process(_handle, out bool is32Bit);
            _is64Bit = !is32Bit;
        }