FileLockItemize

The function returns a delimited list of image file full names for all running processes or services that are currently using a file (i.e.”locked”). Generally, in-use files cannot be deleted, moved to another folder or overwritten.  Typically, files that are opened without sharing enabled are treated as in-use files.  Common examples of in-use files include executable image files of running processes and the .DLL files currently loaded into running processes.  The function returns an empty list, if "filename" is not locked by any process.

Syntax:

FileLockItemize (filename [,flags])

Parameters:

(s) filename: A single absolute or relative path + file name to be checked for locking.

(n) flags: (optional)  Action when "filename" cannot be found.

  @FALSE return an empty list when "filename" is not found  (the default)

  @TRUE   report an error when the file cannot be found.

Returns:

(s) list of locking process' image file names with full paths

 

Note:

This function requires Windows Vista/2008 or newer. It cannot be used to identify the image file of a process running on a remote computer nor will it return the image file names of elevated process when the function is used by a restricted WinBatch process. If a remote process is locking a local file, the function may return a single word like "system" to indicate that the file is in use but that the process is unidentifiable. If only remote processes are locking a remote file on a share and the remote file is tested for locking processes, the function will return an empty string.

Example:

; Determine if any currently running processes
; have WinBatch FileMenu's DLL file loaded.
; (Right-click on a file in an open Windows File
; Explorer window to have an Explorer shell process
; load FileMenu before you run this script.)
; Get the FileMenu installation directory. If WinMetrics(-7) == 0 && WinMetrics(-2) < 3 File = RegQueryValue(@regmachine,"SOFTWARE\Wilson WindowWare\WinBatch\CurrentVersion[]",32):'system\' Else File = RegQueryValue(@regmachine,"SOFTWARE\Wilson WindowWare\WinBatch\CurrentSystem64[]",32) EndIf File := 'FileMenu.dll'
; Get a list of process image files with FileMenu.dll loaded. Exes = FileLockItemize(File) Count = ItemCount(Exes,@tab) If Count == 0 Text = "You haven't used FileMenu recently" ElseIf Count == 1 Text = "You have 1 process using FileMenu" Else Text = "You have ":Count:" processes using FileMenu" EndIf
Message("FileLockItemize Report",Text)
See Also:

FileExist