Microsoft KB Archive/290585

= How to Close All Files Opened by Network Clients from the Command Line =

Article ID: 290585

Article Last Modified on 11/1/2006

-

APPLIES TO


 * 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

-



This article was previously published under Q290585



SUMMARY
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 &quot;skip=4 tokens=1&quot; %a in ('net files') do net files %a /close

The 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  /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 &quot;skip=4 tokens=1&quot; %%a in ('net files') do net files %%a /close

In both cases, this command will appear to return an error because the last line of output from net files is &quot;The Command Completed Successfully&quot; and there is no file ID denoted as &quot;The&quot;.

Note: The Server Service must be running in order for this command to work.

