Powershell: Find process that locks a file: Unterschied zwischen den Versionen
Aus QBWiki
Zur Navigation springenZur Suche springen
Pascal (Diskussion | Beiträge) |
Pascal (Diskussion | Beiträge) |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
| + | Uses the <openfiles> command to find a file-locking process. | ||
| + | Sometimes useful when trying to delete a file. | ||
| − | <syntaxhighlight lang="shell" line="1"> | + | Activate openfiles (Requires Reboot): |
| + | <syntaxhighlight lang="shell"> | ||
| + | openfiles /local on | ||
| + | </syntaxhighlight>Working Pseudeocode example:<syntaxhighlight lang="shell" line="1"> | ||
IF((Test-Path -Path $FileOrFolderPath) -eq $false) { | IF((Test-Path -Path $FileOrFolderPath) -eq $false) { | ||
Write-Warning "File or directory does not exist." | Write-Warning "File or directory does not exist." | ||
Aktuelle Version vom 18. Juni 2019, 08:21 Uhr
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 }