Discussion Locked

Automatically close open files at night?

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a Windows 2000 server running an index database application. My problem is that some of the files are being kept open (on the server) at night and they are interfering with maintenance and the backups. I have the users being forcibly disconnected from the network before the maintenance but these files remain open on the server. I am able to close them manually by going into computer management, shared folders, open files but is there a program or a way of closing these open files at a certain time of night automatically? Thank you,
George

8 replies

by joseph moore

Well, you can do this with a BAT file. I love BAT files!

Anyway, the command NET FILES will give you all open files/pipes, with their unique ID. For example, when I run a NET FILES on a server here, I get the following:

ID Path User name # Locks

-------------------------------------------------------------------------------
291823 \PIPE\llsrpc 0
784515 \PIPE\spoolss kstrack 0
785386 \PIPE\llsrpc 0
827811 \PIPE\samr 0
836081 \PIPE\llsrpc 0
836248 \PIPE\llsrpc 0
889059 D:\ACCOUNT\2003\Codes 2003.xls USER1 3
890997 D:\ACCOUNT\...licy modified 17nov03.doc USER1 3

by joseph moore

Ok, so the NET FILES gives you the open files and the connection pipes. You want to close them all automatically. Sure. NET FILES has a /CLOSE switch that will close the file listed. But you need the file ID. That syntax is:
NET FILES ### /CLOSE

But, the file IDs will change each time a file is opened. What to do?????

Run this BAT file to collect the NET FILE information (including the file ID#), then to parse throught the output and close them. This BAT will make a text file called NETFILES.TXT that contains the NET FILES info, then use that text file to get the file IDs and then close them.

@echo off
cls
NET FILES >netfiles.txt
FOR /F "SKIP=4 TOKENS=1-3 DELIMS= " %%I IN (NETFILES.TXT) DO NET FILES %%I /CLOSE
DEL NETFILES.TXT
EXIT

by joseph moore

This will close everything running in the NET FILES list, and it skips the first 4 lines, which are file header info.

The only error is that the last line of the NET FILES output is the message "the command completed successfully." So, once all the file IDs are ran through and closed, the BAT file will try and do a "net files THE /close" which will, obviously, fail. But that is the only error, and that is after all open files are closed.

So, good luck.

hope this helps

by joseph moore

Oh, I probably ought to add that you should just save the BAT file somewhere, then schedule it to run as a Scheduled Task. Have it run at night, when everyone has left the office, and run on the machine that hosts the files, like a central file server. This does NOT work over a network connection. You need to run the BAT file on the server that holds the files you want to close.

by first_wd40

You should had already checked this but here it is anyways.. The maint. and backup software, does it have an option in it to close the files?
I know most backup software has an option of what to do before and one for after. Also some backup has an add on to backup open files.

This discussion is closed to new replies.