Display a list of open files
With /query
, openfiles
displays the list of open files.
C:\> openfiles /query /fo table
Files Opened Locally:
---------------------
ID Process Name Open File (Path\executable)
===== ==================== ==================================================
64 fontdrvhost.exe C:\Windows\System32
64 fontdrvhost.exe C:\Windows\System32
64 dwm.exe C:\Windows\System32
212 dwm.exe C:\Windows\System32\en-US\dwm.exe.mui
388 dwm.exe C:\Windows\System32\en-US\d2d1.dll.mui
1556 dwm.exe C:\Windows\System32\en-US\crypt32.dll.mui
2168 dwm.exe C:\Windows\System32\en-US\KernelBase.dll.mui
2212 dwm.exe C:\Windows\System32
…
Note that the column
ID
does not identify a
process id?
In order to get the process id also, the /v
(verbose) flag must be given:
openfiles /query /fo table /v
Files Opened Locally:
---------------------
ID Accessed By PID Process Name Open File (Path\executable)
===== =============== ======== ==================== ================================================================================
64 UMFD-0 1000 fontdrvhost.exe C:\Windows\System32
64 UMFD-1 1256 fontdrvhost.exe C:\Windows\System32
64 DWM-1 1328 dwm.exe C:\Windows\System32
212 DWM-1 1328 dwm.exe C:\Windows\System32\en-US\dwm.exe.mui
388 DWM-1 1328 dwm.exe C:\Windows\System32\en-US\d2d1.dll.mui
1556 DWM-1 1328 dwm.exe C:\Windows\System32\en-US\crypt32.dll.mui
…
Example
Trying to move (rename) a directory in
PowerShell:
PS C:\Users\rene> mv proj proj.old
move : Access to the path 'C:\Users\Rene\proj\' is denied.
Become administrator:
PS C:\Users\rene> start-process $( (get-process -pid $pid).path ) -verb runAs
Be prepared for the followign command to take some time until it is finished…
PS C:\Windows\System32> openfiles /query /fo table /v | select-string 'C:\\Users\\rene\\proj'
11376 Rene 60 explorer.exe C:\Users\Rene\proj\some\sub\directory
13644 Rene 60 explorer.exe C:\Users\Rene\proj\another\sub\directory
stop-process -id 60