Exemplo n.º 1
0
        public bool UnlockProcess(Process ra3Process, Pinvokes.ProcessAccessFlags flags)
        {
            LockProcess();

            Logger.Debug($"attempt to unlock process (open process). using pid {ra3Process.Id}");
            IntPtr tmpHandle = Pinvokes.OpenProcess(
                flags
                , false
                , ra3Process.Id
                );

            if (tmpHandle != IntPtr.Zero)
            {
                _processUnlocked = true;
                Handle           = tmpHandle;
                Ra3ProcessHandle.Add(tmpHandle, ra3Process);
                Logger.Debug("OK.. unlock process (open process)");
                return(true);
            }

            _processUnlocked = false;
            int errCode = Marshal.GetLastWin32Error();

            Logger.Error($"ER.. unlock process (open process). code: {errCode}");
            return(false);
        }
Exemplo n.º 2
0
        public bool LockProcess()
        {
            if (Handle != IntPtr.Zero &&
                Ra3ProcessHandle.ContainsKey(Handle) &&
                Ra3ProcessHandle[Handle].HasExited == false)
            {
                Logger.Debug("attempt to lock process (close handle)");
                if (Pinvokes.CloseHandle(Handle))
                {
                    Ra3ProcessHandle.Remove(Handle);
                    Handle           = IntPtr.Zero;
                    _processUnlocked = false;
                    Logger.Debug("OK.. lock process (close handle)");
                }
                else
                {
                    int errCode = Marshal.GetLastWin32Error();
                    Logger.Error($"ER.. lock process (close handle). code: {errCode}");
                }
            }

            Logger.Debug("no process or handle found that could be closed");
            return(true);
        }