Powershell - check if file is being used

Is there a Powershell command to check if a file is being used by another user? If not, what would it take to write a script that can?

+3
source share
3 answers

You cannot tell if a file is used only if it has been used recently. The reason is that the moment the script returns the file can be closed by any program that previously used it. Writing scripts like this will only lead to poor performance.

A much better approach is to just do what the script planned if the file was not used and catch exceptions that result from a usage conflict. The end result will be a much simpler and more reliable program.

+4
source

There is no built-in command that I know of, however there are a few tools you can use to do this:

net file

From SysInternals to Technet ( psfile and handle ):

psfile.exe # lists and allows you to close remotely opened files

handle.exe | select-string ': File'
+4
source

, SysInternals "ListDlls.exe" :

c:\SysInternals\Listdlls.exe -d AssemblyInUse.dll

ListDLLs v3.1 - List loaded DLLs
Copyright (C) 1997-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

----------------------------------------------------------------------------
powershell.exe pid: 7296
Command line: "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe"

, !

+1

Source: https://habr.com/ru/post/1761753/


All Articles