Powershell: Find process that locks a file

Aus QBWiki
Version vom 18. Juni 2019, 08:21 Uhr von Pascal (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

Zur Navigation springenZur Suche springen


Uses the <openfiles> command to find a file-locking process.

Sometimes useful when trying to delete a file.

Activate openfiles (Requires Reboot):

openfiles /local on

Working Pseudeocode example:

1 IF((Test-Path -Path $FileOrFolderPath) -eq $false) {
2     Write-Warning "File or directory does not exist."       
3 }
4 Else {
5     $LockingProcess = CMD /C "openfiles /query /fo table | find /I ""$FileOrFolderPath"""
6     Write-Host $LockingProcess
7 }