How to Close All Files Opened by Network Clients from the Command Line
This article was previously published under Q290585
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes how to close all open files on a Windows NT 4.0-based computer or Windows 2000-based computer from the command line. You can use this command to close files on the computer where the files reside, which you may find most useful when you run it prior to backup procedures in environments where users do not log off, disconnect, or close files prior to scheduled backup procedures. This command only affects files that are open from SMB clients. It does not affect interprocess communication (IPC) or remote procedure call (RPC) connections, HTTP requests, or files that are in use by FTP clients.
Note: This command closes all open shared files and removes the file locks of these files; It in no way attempts to understand the nature of the files or the client programs that have the files open. In some cases data loss may occur if users have not saved the files prior to the use of this command. It is recommended that you test this command in your enviroment prior to its application in a production capacity.
Command to Close All Open Files
for /f "skip=4 tokens=1" %a in ('net files') do net files %a /closeThe command works by passing the file ID elements from the list produced by the net files command to the action argument of the for command, net files file ID /close. When you use the iterative substitution (%a in this case) as part of a batch file, the substitution needs to be %%a. For the batch file version of the command, use the following syntax:
for /f "skip=4 tokens=1" %%a in ('net files') do net files %%a /closeIn both cases, this command will appear to return an error because the last line of output from net files is "The Command Completed Successfully" and there is no file ID denoted as "The".
Note: The Server Service must be running in order for this command to work.
For more information about these commands, from the command line type:
net help files
Article ID: 290585 - Last Review: 12/06/2015 00:52:07 - Revision: 2.2
Microsoft Windows 2000 Server, Microsoft Windows 2000 Professional Edition, Microsoft Windows NT Workstation 4.0 Developer Edition, Microsoft Windows NT Server 4.0 Standard Edition
- kbnosurvey kbarchive kbhowto kbnetwork KB290585