Linux 如何确定特定文件是否在 Windows 中打开?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15708/
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-08-03 16:20:51  来源:igfitidea点击:

How can I determine whether a specific file is open in Windows?

windowslinuxcommand-linefilesystems

提问by Daniel Fone

One of my favourite tools for linux is lsof- a real swiss army knife!

我最喜欢的 Linux 工具之一是lsof——一把真正的瑞士军刀!

Today I found myself wondering which programs on a WinXP system had a specific file open. Is there any equivalent utility to lsof? Additionally, the file in question was over a network share so I'm not sure if that complicates matters.

今天我发现自己想知道 WinXP 系统上的哪些程序打开了特定文件。是否有与 lsof 等效的实用程序?此外,有问题的文件是通过网络共享的,所以我不确定这是否会使问题复杂化。

采纳答案by Jay Hofacker

Use Process Explorerfrom the Sysinternals Suite, the Find Handle or DLL function will let you search for the process with that file open.

使用Sysinternals Suite 中的进程资源管理器,查找句柄或 DLL 函数将让您搜索打开该文件的进程。

回答by Matt Hamilton

If you right-click on your "Computer" (or "My Computer") icon and select "Manage" from the pop-up menu, that'll take you to the Computer Management console.

如果您右键单击“计算机”(或“我的电脑”)图标并从弹出菜单中选择“管理”,则会将您带到计算机管理控制台。

In there, under System Tools\Shared Folders, you'll find "Open Files". This is probably close to what you want, but if the file is on a network share then you'd need to do the same thing on the server on which the file lives.

在那里,在系统工具\共享文件夹下,您会找到“打开文件”。这可能与您想要的很接近,但是如果文件位于网络共享上,那么您需要在文件所在的服务器上执行相同的操作。

回答by slipsec

Try Handle. Filemon& Regmonare also great for trying to figure out what the duce program foo is doing to your system.

尝试处理FilemonRegmon也非常适合尝试弄清楚 duce 程序 foo 对您的系统做了什么。

回答by Greg Mattes

Try Unlocker.

试试解锁器

The Unlocker site has a nifty chart (scroll down after following the link) that shows a comparison to other tools. Obviously such comparisons are usually biased since they are typically written by the tool author, but the chart at least lists the alternatives so that you can try them for yourself.

Unlocker 站点有一个漂亮的图表(点击链接后向下滚动),显示了与其他工具的比较。显然,这种比较通常是有偏见的,因为它们通常是由工具作者编写的,但图表至少列出了替代方案,以便您可以自己尝试。

回答by Greg Mattes

The equivalent of lsof -p pidis the combined output from sysinternals handle and listdlls, ie

相当于lsof -p pid是来自 sysinternals handle 和 listdlls 的组合输出,即

handle -p pid
listdlls -p pid

you can find out pid with sysinternals pslist.

您可以使用 sysinternals 找出 pid pslist

回答by Sean

If the file is a .dll then you can use the TaskListcommand line app to see whose got it open:

如果文件是 .dll,那么您可以使用TaskList命令行应用程序查看谁打开了它:

TaskList /M nameof.dll

回答by pushNpop

Use Process Explorer to find the process id. Then use Handleto find out what files are open.

使用 Process Explorer 查找进程 ID。然后使用Handle找出打开了哪些文件。

Eg handle -p

例如句柄 -p

I like this approach because you are using utilities from Microsoft itself.

我喜欢这种方法,因为您使用的是 Microsoft 本身的实用程序。

回答by M8R-qpgep8

In OpenedFilesView, under the Options menu, there is a menu item named "Show Network Files". Perhaps with that enabled, the aforementioned utility is of some use.

OpenedFilesView 中,在 Options 菜单下,有一个名为“Show Network Files”的菜单项。也许启用该功能后,上述实用程序会有一些用处。

回答by Alois Mahdal

One equivalent of lsofcould be combined output from Sysinternals' handleand listdlls, i.e.:

一个等效的lsof可以组合来自 Sysinternals 的handlelistdlls 的输出,即:

c:\SysInternals>handle
[...]
------------------------------------------------------------------------------
gvim.exe pid: 5380 FOO\alois.mahdal
   10: File  (RW-)   C:\Windows
   1C: File  (RW-)   D:\some\locked\path\OpenFile.txt
[...]

c:\SysInternals>listdlls
[...]
------------------------------------------------------------------------------
Listdlls.exe pid: 6840
Command line: listdlls

  Base        Size      Version         Path
  0x00400000  0x29000   2.25.0000.0000  D:\opt\SysinternalsSuite\Listdlls.exe
  0x76ed0000  0x180000  6.01.7601.17725  C:\Windows\SysWOW64\ntdll.dll
[...]

c:\SysInternals>listdlls

Unfortunately, you have to "run as Administrator" to be able to use them.

不幸的是,您必须“以管理员身份运行”才能使用它们。

Also listdllsand handledo not produce continuous table-like form so filtering filename would hide PID. findstr /c:pid: /c:<filename>should get you very close with both utilities, though

此外,listdllshandle不会产生连续的类似表格的形式,因此过滤文件名会隐藏 PID。findstr /c:pid: /c:<filename>应该让你非常接近这两个实用程序,虽然

c:\SysinternalsSuite>handle | findstr /c:pid: /c:Driver.pm
System pid: 4 \<unable to open process>
smss.exe pid: 308 NT AUTHORITY\SYSTEM
avgrsa.exe pid: 384 NT AUTHORITY\SYSTEM
[...]
cmd.exe pid: 7140 FOO\alois.mahdal
conhost.exe pid: 1212 FOO\alois.mahdal
gvim.exe pid: 3408 FOO\alois.mahdal
  188: File  (RW-)   D:\some\locked\path\OpenFile.txt
taskmgr.exe pid: 6016 FOO\alois.mahdal
[...]

Here we can see that gvim.exe is the one having this file open.

在这里我们可以看到 gvim.exe 是打开这个文件的那个。

回答by anonymous

There is a program "OpenFiles", seems to be part of windows 7. Seems that it can do what you want. It can list files opened by remote users (through file share) and, after calling "openfiles /Local on" and a system restart, it should be able to show files opened locally. The latter is said to have performance penalties.

有一个程序“OpenFiles”,似乎是 Windows 7 的一部分。似乎它可以做你想做的事。它可以列出远程用户打开的文件(通过文件共享),并且在调用“openfiles /Local on”并重新启动系统后,它应该能够显示本地打开的文件。据说后者有性能损失。