close an open file by name

  • Thread starter Thread starter drdraxx
  • Start date Start date
D

drdraxx

I'm looking for a way to be able to close an open file by name on a
Windows 2003 Server Standard automatically. In a few google searches,
I found people listing a command to close all open files:

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

and one to close individual files:

net file ID /close

The problem with that is knowing the file ID. To test I tried to open
a file on the server, check the ID, close the file and open it again
but the ID changed. Does anyone know of a method I could use to close
one specific file by name by say a scheduled task or .bat file or
anything like that?
 
"drdraxx" <drdraxx@gmail.com> wrote in message
news:1184952859.985132.187460@g12g2000prg.googlegroups.com...
> I'm looking for a way to be able to close an open file by name on a
> Windows 2003 Server Standard automatically. In a few google searches,
> I found people listing a command to close all open files:
>
> for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close
>
> and one to close individual files:
>
> net file ID /close
>
> The problem with that is knowing the file ID. To test I tried to open
> a file on the server, check the ID, close the file and open it again
> but the ID changed. Does anyone know of a method I could use to close
> one specific file by name by say a scheduled task or .bat file or
> anything like that?
>


You could try oh.exe to obtain the file ID of an open file. Oh.exe
comes with the Windows Resource Kit.
 
On Jul 23, 11:55 am, "Brian Spolarich" <bria...@gmail.com> wrote:
> "drdraxx" <drdr...@gmail.com> wrote in message
>
> news:1184952859.985132.187460@g12g2000prg.googlegroups.com...
>
> > I'm looking for a way to be able to close an open file by name on a
> > Windows 2003 Server Standard automatically.

>
> psfile does this quite well for shared files.
>
> http://www.microsoft.com/technet/sysinternals/Utilities/PsTools.mspx



Thank you for the help. Before I actually saw this response, I
figured it out. I had to change up the "for /f "skip=4 tokens=1" %a
in ('net files') do net files %a /close " command to take more tokens
and do an if statement. Here is what I ended up using in a .bat file:

@echo off
for /f "skip=4 tokens=1,3*" %%a in ('net files') do if %%b == [path
\filename I was looking for] net files %%a /close

This basically took the ID and stored it in variable a and took the
path and stored it in variable b. The loop then just went line by
line through the net files list (starting at line 4 from the skip) and
did a compair on the path\filename I was looking for. If it found it,
then it would close the file with the ID tag it got from the same
line.
 
Back
Top