Forcing closed an open file by C#

前端 未结 3 605
感情败类
感情败类 2021-01-04 03:44

I found a similar question here but it was closed/accepted with an answer of \"don\'t do that\".

I\'m in a situation where I don\'t care what happens to the other ap

3条回答
  •  耶瑟儿~
    2021-01-04 04:11

        foreach (var process in Process.GetProcessesByName("excel")) //whatever you need to close 
        {
            if (process.MainWindowTitle.Contains("test.xlsx"))
            {
                process.Kill();
                break;
            }
        }
    

    or

        foreach (var process in Process.GetProcesses())
        {
            if (process.MainWindowTitle.Contains("test.dat"))
            {
                process.Kill();
                break;
            }
        }
    

提交回复
热议问题