How to Close All Files Opened by Network Clients from the Command Line (290585)



The information in this article applies to:

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Professional
  • Microsoft Windows NT Workstation 4.0
  • Microsoft Windows NT Server 4.0

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.

MORE INFORMATION

Command to Close All Open Files

for /f "skip=4 tokens=1" %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 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 /close

In 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.

REFERENCES

For more information about these commands, from the command line type:

net help files

and

for /?


Modification Type:MinorLast Reviewed:1/25/2006
Keywords:kbhowto kbnetwork KB290585