根据文件路径,强制关闭所有占用文件的进程

解决方案 »

  1.   

     Process[] pcs = Process.GetProcesses();
                foreach (Process p in pcs)
                {
                    if (p.MainModule.FileName == "你的文件路径")
                    {
                        p.Kill();
                    }
                } 百度一下基本就又得
      

  2.   


    1、引发了“System.ComponentModel.Win32Exception”类型的异常
    2、没有根据路径找到对应的进程
      

  3.   

    可能会因为太深入底层 拒绝访问之类的
    你可以类似这样去实现    Process[] pcs = Process.GetProcesses();
                foreach (Process p in pcs)
                {
                    //确定文件进程名
                    if (p.ProcessName == "notepad")
                    {
                        //确认文件
                        if (p.MainWindowTitle.Contains("新建文本文档.txt"))
                        {
                            p.Kill();//结束进程
                        }                }
                }
      

  4.   

    具体你去Debug处理好了
      

  5.   


    public static void KillFile(string fileName)
            {
                if (IsFileInUse(fileName))
                {
                    Process tool = new Process();
                    tool.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\handle64.exe";
                    tool.StartInfo.Arguments = fileName + " /accepteula";
                    tool.StartInfo.UseShellExecute = false;
                    tool.StartInfo.RedirectStandardOutput = true;
                    tool.Start();
                    tool.WaitForExit();
                    string outputTool = tool.StandardOutput.ReadToEnd();                string matchPattern = @"(?<=\s+pid:\s+)\b(\d+)\b(?=\s+)";
                    foreach (Match match in Regex.Matches(outputTool, matchPattern))
                    {
                        Process.GetProcessById(int.Parse(match.Value)).InitializeLifetimeService();
                    }
                }
            }
      

  6.   


    1、引发了“System.ComponentModel.Win32Exception”类型的异常
    2、没有根据路径找到对应的进程他说的是关占用文件的进程,不见得是关文件本身,
    我有一个文件A,正在用迅雷下载,那么这个文件就被迅雷占用着,楼主的提问是杀掉迅雷。
      

  7.   

    这不就是wholockme嘛