用于检查锁定文件的应用程序的 PowerShell 脚本?

标签 powershell scripting filelock

在 PowerShell 中使用,如何检查应用程序是否锁定文件?

我喜欢检查哪个进程/应用程序正在使用该文件,以便我可以关闭它。

最佳答案

您可以使用 SysInternals tool handle.exe 来执行此操作。尝试这样的事情:

PS> $handleOut = handle
PS> foreach ($line in $handleOut) { 
        if ($line -match '\S+\spid:') {
            $exe = $line
        } 
        elseif ($line -match 'C:\\Windows\\Fonts\\segoeui\.ttf')  { 
            "$exe - $line"
        }
     }
MSASCui.exe pid: 5608 ACME\hillr -   568: File  (---)   C:\Windows\Fonts\segoeui.ttf
...

关于用于检查锁定文件的应用程序的 PowerShell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/958123/

相关文章:

powershell - 在 VSCode 集成终端内运行时如何自定义 powershell?

powershell - 在 PowerShell 管道 $_ 变量中使用属性名称

powershell - Win32_processor仅显示CPU0

linux - 如何在 shell 脚本中异步运行迭代

scripting - 24小时内最容易学习的脚本语言?

c# - 如何检查文件锁定?

powershell - 术语 'Get-WebBinding' 未被识别为 cmdlet、函数、脚本文件或可操作程序的名称

scripting - 对您有很大帮助的小工具/脚本?

java - 无法使用 java.nio.channels.FileLock 在 Linux 上锁定文件