Out of the many data files on your server, it seems like multiple users always try to access the same file. And, when they can’t access the file or don’t know who may be using it, they always call the network administrator. How do you resolve the situation? You can identify who has a file open and then close it using the Net Files command.
Lock and load
Unless the application is a database program working with a multiuser database, when an application accesses a data file on the network, it places a lock on the file. This lock prevents multiple users from accessing the file at the same time. Without a file lock, two users could open the same file, make changes and then save the file, which could result in data loss or corruption.
Some applications, such as Word and Excel, will tell you the file is in use and by whom. They will also allow you to open a temporary version of the document and warn you that your changes won’t be reflected in the original document. Other applications, especially custom-written ones, won’t do this. In the best cases, they’ll just tell you the file is locked and you can’t access it. In others, users may receive weird error messages or experience application failures.
Even though file locks in and of themselves are good, they can cause problems if users are careless. For example, if a user opens a file and leaves for an extended period of time, no one else can access the file. Even though Microsoft Word tells you that Bob has the file open, it’s not much help if he’s gone for the day.
That’s where the Net Files command comes in handy. It will help you both identify open files and close them if you need to.
Caveats
The biggest thing to remember about the Net Files command is if you close a file, the user loses any unsaved changes. To avoid data loss or corruption, use the command sparingly.
Also, be aware that Net Files only shows and works with files that are opened by SMB clients. It won’t show files that are opened by HTTP requests, FTP requests, interprocess communication (IPC) requests, or remote procedure call (RPC) requests.
Running the command
To run the command, open a command prompt on your Windows server. You can’t run it from your administration workstation. The Net Files command only works on the server you’re running it on, not across multiple servers. So check with the user first to find out what server he or she is loading the files from. If the user doesn’t know, just ask for the drive letter and check your drive mapping documentation to find the server on which to run the command.
At the command prompt, type net files and press [Enter]. You’ll see a list of files appear onscreen broken down into four columns: ID, Path, User Name, and # Locks. You’ll need the ID number to close the file. The Path column shows you the name and directory location of any open files on your server. The User Name column reflects the user ID of the person who has the file open. Finally, the # Locks column shows you if the file is locked.
If you have a large number of users on your network, you may notice that the output of the Net Files command whizzes off the top of the screen, causing you to miss the file and username you’re looking for. If that occurs, you can do one of two things. First, you can type net files | more and press [Enter]. This will cause the Net Files command to fill one screen and then pause until you press a key, at which point it will fill another screen. When you find the file you want, press [Ctrl]C to abort the list.
An alternative is to type net files >file.lst and press [Enter]. This will cause Net Files to spool its output to a file called Files.lst. You can then load this file into any text editor and use the editor’s Find command to search for the locked file.
After you’ve located the file in question, you can close it if you need to. Try to contact the user who has the file open first, because when you close it, the user will lose any unsaved changes to the file. If you can’t contact the user but the second user still needs to access the file, type net files IDnumber /close where you replace ID number with the value for the file found in the ID column. The server will close the file and the second user will then be able to access it.
If you want to close all of your files at once, for instance if you’re working over the weekend and users have left many files open that you need to close to do important maintenance, you can. It just takes a bit of scripting. The script to cause Net Files to close all open files is: for /f “skip=4 tokens=1” %a in (‘net files’) do net files %a /close. Drop to a command prompt, cut and paste this command into your command window, and press [Enter]. This will cause every file on your server to close, so use extreme caution when running it.