windows 文件被另一个进程使用。如何知道是哪个进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3386157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:56:58  来源:igfitidea点击:

File is used by another process. How to know which process?

.netwindowsfile-access

提问by Louis Rhys

I keep getting that exception in my program. How do I know which process locked it, either by program code or by doing something with windows?

我的程序中不断收到该异常。我怎么知道哪个进程锁定了它,是通过程序代码还是通过对 Windows 执行某些操作?

System.IO.IOException : The process cannot access the file 'file.ext' because it is being used by another process.

System.IO.IOException : The process cannot access the file 'file.ext' because it is being used by another process.

回答by Justin

You can use ProcessExplorer to search for the file:

您可以使用 ProcessExplorer 来搜索文件:

Just run that (maybe you need to launch it with administrator rights), hit Ctrl-Fand type in the name of the file which is locked - it will find all open handles which match the given name, and tell you which process it belongs to.

只需运行它(也许您需要以管理员权限启动它),点击Ctrl-F并输入被锁定文件的名称 - 它会找到与给定名称匹配的所有打开的句柄,并告诉您它属于哪个进程。

回答by Oded

You can use a tool like ProcessMonto see what process is locking a file.

您可以使用类似工具ProcessMon查看锁定文件的进程。

回答by royse41

Have a look at this: http://www.emptyloop.com/unlocker/

看看这个:http: //www.emptyloop.com/unlocker/

I use it all the time, tells you which process has locked it and gives you the chance to unlock it fully. Useful especially for when your debugging image manipulation apps and it bombs out without closing the file properly.

我一直在使用它,告诉您哪个进程锁定了它,并让您有机会完全解锁它。特别适用于调试图像处理应用程序并且它在没有正确关闭文件的情况下爆炸的情况。

Hope this helps!

希望这可以帮助!

Sean

肖恩