Last active
May 25, 2020 13:56
-
-
Save sakyaer/058c506c2cdea35cac0b6a25a89ea833 to your computer and use it in GitHub Desktop.
|-|{"files":{"CallExteralExe.csharp":{"env":"plain","abbr":""}},"tag":"C#"}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string fileName = @"c:\aaa.doc";//要检查被那个进程占用的文件 | |
Process tool = new Process(); | |
tool.StartInfo.FileName = "handle.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)).Kill(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment