示例#1
0
        public static bool ClearMutex(int ProID, string MutexName)
        {
            bool success = false;

            if (HandleManager.KillHandle(Process.GetProcessById(ProID), MutexName, false))
            {
                success = true;
            }


            return(success);
        }
示例#2
0
        /// <summary>
        /// Kills named mutex in active process.
        /// </summary>
        /// <param name="Proc">Full path to process file to unlock from</param>
        /// <param name="MutexName">Full name of mutex to be removed</param>
        /// <param name="excProcIDs">Process ID's to exclude</param>
        /// <returns></returns>
        public static bool ClearMutex(string ProcName, string MutexName, ref List <int> excProcIDs)
        {
            bool success = false;
            var  excList = excProcIDs == null ? new List <int>() : excProcIDs.ToList();

            //get list of currently running system processes
            Process[] processList = Process.GetProcesses();

            foreach (Process i in processList.Where(a => !excList.Contains(a.Id)).Where(a => a.ProcessName.Equals(ProcName, StringComparison.OrdinalIgnoreCase)))
            {
                if (HandleManager.KillHandle(i, MutexName, false))
                {
                    success = true;
                    excProcIDs.Add(i.Id);
                }
            }

            return(success);
        }
示例#3
0
        /// <summary>
        /// Clears file locks on the specified file, from specified process.
        /// </summary>
        /// <param name="Proc">Full path to process file to unlock from</param>
        /// <param name="File">Full path to file to be unlocked</param>
        /// <param name="excProcIDs">Process ID's to exclude</param>
        /// <returns></returns>
        public static bool ClearFileLock(string ProcName, string File, ref List <int> excProcIDs)
        {
            bool success = false;
            var  excList = excProcIDs == null ? new List <int>() : excProcIDs.ToList();

            //take off the drive portion due to limitation in how killhandle works for file name
            File = File.Substring(2);

            //get list of currently running system processes
            Process[] processList = Process.GetProcesses();

            foreach (Process i in processList.Where(a => !excList.Contains(a.Id)).Where(a => a.ProcessName.Equals(ProcName, StringComparison.OrdinalIgnoreCase)))
            {
                if (HandleManager.KillHandle(i, File, true))
                {
                    success = true;
                    excProcIDs.Add(i.Id);
                }
            }

            return(success);
        }
示例#4
0
        /// <summary>
        /// Clears file locks on the specified dat file, from specified process.
        /// </summary>
        /// <param name="Proc">Full path to process file to unlock from</param>
        /// <param name="Dat">Full path to dat file to be unlocked</param>
        /// <param name="excProcIDs">Process ID's to exclude</param>
        /// <returns></returns>
        public static bool ClearDatLock(string Proc, string Dat, ref List <int> excProcIDs)
        {
            bool success = false;
            var  excList = excProcIDs == null ? new List <int>() : excProcIDs.ToList();

            //take off the drive portion due to limitation in how killhandle works for file name
            Dat = Dat.Substring(2);

            //get list of currently running system processes
            Process[] processList = Process.GetProcesses();

            foreach (Process i in processList.Where(a => !excList.Contains(a.Id)).Where(a => a.ProcessName.Equals(Regex.Replace(Proc, @"\.exe(?=[^.]*$)", "", RegexOptions.IgnoreCase), StringComparison.OrdinalIgnoreCase)))
            {
                if (HandleManager.KillHandle(i, Dat, true))
                {
                    success = true;
                    excProcIDs.Add(i.Id);
                }
            }

            return(success);
        }