Windows

Close all files from the command line in Windows 2000 Server

If you're doing maintenance on your Windows 2000 Server, it’s important to do a comprehensive shutdown from time to time. Jim Boyce gives the rundown on making sure everything is closed before you dig in.

Maintaining busy servers is far from easy. You not only have to keep them up and running, but you also have to make sure the resources are available to users on your Windows 2000 Server. However, there are times when you'll want to close those resources—such as before doing a maintenance backup or other activity that requires exclusive access to resources.

Several UI tools will close opened files. To use Computer Management to close open files, run the management console and expand System Tools | Shared Folders | Open Files. Then, right-click an individual file to close the file, or right-click the Open Files node to close them all at once.

You can automate this process by using a command line. Typing the following command will close all files opened by network clients:

for /f
"skip=4 tokens=1" %a in ('net files') do net files %a /close

This command executes the net files /close command on all files from the net files list. Because the last entry on the net files list is not a file, you’ll get an error message even though all files were closed.

If you want to use net files in a batch file, you have to use a slightly different syntax:

for /f "skip=4 tokens=1" %%a
in ('net files') do net files %%a /close

Miss a column?

Check out the Windows 2000 Server archive, and catch up on the most recent editions of Jim Boyce's column.

Want more Win2K tips and tricks? Automatically sign up for our free Windows 2000 Server newsletter, delivered each Tuesday!

0 comments

Editor's Picks