How to tell who has a file open on a server
net file | find ".doc" /i.
To see which files are open on a remote PC, you can use OFL, the Open File List Utility. OFL lists files on a specified Server which have been opened via a network connection. The user running this utility must be either an Operator or an Administrator on the server.
This is the way that I use this utility:
Note: Right now, the way I have it set up only allows you to check on a named server that you specify in a batch file.
1) Copy ofl.exe to C:\Winnt\system32.
2) Create a batch file, ofl.bat, and also copy it to C:\Winnt\system32.
The batch file contains:
for /f "Tokens=*" %%i in ('dir /B /O') do C:\Winnt\system32\ofl.exe -d -s ServerName "%%i" | find "D:"
Notes: D: is the the actual drive letter on the server, not the mapped drive. %% must be used within a batch file, if you run this directly from the command line just use %.
3) Create and import a registry file that will give you a context menu when you right click.
[HKEY_CLASSES_ROOT\Directory\shell\Who Has This Open]
[HKEY_CLASSES_ROOT\Directory\shell\Who Has This Open\Command]
With this is in place, I can map ServerName to a drive letter on my PC and then navigate to where I want to check for an open file. Once I am there, I right click on the directory name (in the left Explorer pane) and choose Who Has This Open. The for loop will go though all of the files in that directory. The Find command will limit the output to only lines that contain the actual drive letter that ServerName is sharing and that I am mapped to.
I have a server called NTServer that is mapped to I: on my PC, but the drive letter is actually F: on the server itself. With that in mind, the relevant line in my batch file is:
for /f "Tokens=*" %%i in ('dir /B /O') do C:\WINNT\System32\ofl.exe -d -s NTServer "%%i" | find "F:"
I want to see what files are open under I:\FILES\Fmpro3 (again, I: is actually F: on the server itself). When I right click on Fmpro3 in the left pane of the Explorer window and choose Who Has This Open, a DOS window returns:
4f6ef RW---A-- 0 username1 F:\FILES\Fmpro3\mp3.FP3
4f653 RW---A-- 0 username5 F:\FILES\Fmpro3\urls.FP3
I can tell that username1 has 1 file open and that username5 has the other file open.
Also see: http://www.sysinternals.com/ntw2k/freeware/psfile.shtml
Additional notes will be added as time allows. It should be fairly easy to use the choice command to let you choose from a list of commands to actually run from the batch file.