我在嘗試使用.mkv文件(vlc.exe,mpc-hc.exe等)進程的名稱如何找出正在使用哪個進程的文件
我已經設法發現它是否在使用中,但我想知道至關重要的進程正在使用該文件。
我試過了這個帖子How do I find out which process is locking a file using .NET?的建議,但只是插入文件的路徑並運行它似乎沒有工作,它沒有顯示任何進程(我可以運行代碼沒有錯誤)。
public static bool IsFileinUse(FileInfo file)
{
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
finally
{
if (stream != null)
stream.Close();
}
return false;
}
這可以幫助你在正確的方向走http://stackoverflow.com/questions/958123/powershell-script-to-check-an-application-這就是鎖定文件 –
http://stackoverflow.com/questions/317071/how-do-i-find-out-which-process-is-locking-a-file-using-net –
http:// stackoverflow.com/questions/860656/using-c-how-does-one-figure-out-what-process-locked-a-file –