0

i use winrar to extract a rar file in my application. after that extract is compete i need to move the extracted file but it some times it has this error: The process cannot access the file because it is being used by another process

i guess that error is Regarding to winrar so i kill winrar process but the error exist

I use (Process.HasExited ) to force program to sleep for 5 minute i can kill process but have following problem: but The process cannot access the file because it is being used by another process and use code for kill process :

 try
            {
                Process proc = Process.GetProcessById(id);
                proc.Kill();
            }
            catch (Exception ex)
            {
                Process[] processlist = Process.GetProcesses();
                foreach (Process p in Process.GetProcesses("."))
                {
                    try
                    {
                        if (p.ProcessName.ToLower().Contains("winrar"))
                        {
                            string str =            Bussiness.ClsCommandLine.GetCommandLine(p);
                            if (str.ToLower().Contains((fileName.ToLower()))
                            {
                                Process prc = Process.GetProcessById(p.Id);
                                prc.Kill();
                            }
                        }
                    }
                    catch (Exception ex1)
                    {
                        result = false;
                    }
                }
            }

any idea?

aira
  • 3
  • 3

1 Answers1

0

Cant comment, so i have to add as an answer :

(assuming you are on win vista onwards) Use resource monitor to look through the associated handles (resource monitor -> CPU -> check all checkboxes -> associated handles) and look for any processes (images) that have a Handle on the files that you are trying to move

For example, the Image "winrar.exe" could have "c:\users\~username\my documents\directory\uncompressedfile.file"

This should give you an idea of what has a hold of the files you are trying to read/modify/

Byren Higgin
  • 552
  • 4
  • 13
  • use code for kill process: Process proc = Process.GetProcessById(id); proc.Kill(); – aira Dec 16 '15 at 05:30
  • and exception use :Process[] processlist = Process.GetProcesses(); foreach (Process p in Process.GetProcesses(".")) { if (p.ProcessName.Contains("Winrar")) { string str = Bussiness.ClsCommandLine.GetCommandLine(p); if (str.Contains(fileName) { Process prc = Process.GetProcessById(p.Id); prc.Kill(); } } – aira Dec 16 '15 at 05:35