Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



close an open file by name

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 21-07-2007
drdraxx
 
Posts: n/a
close an open file by name

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?


Reply With Quote
  #2  
Old 21-07-2007
Pegasus \(MVP\)
 
Posts: n/a
Re: close an open file by name


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


Reply With Quote
  #3  
Old 24-07-2007
Brian Spolarich
 
Posts: n/a
Re: close an open file by name


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


psfile does this quite well for shared files.

http://www.microsoft.com/technet/sys...s/PsTools.mspx




Reply With Quote
  #4  
Old 24-07-2007
drdraxx
 
Posts: n/a
Re: close an open file by name

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/sys...s/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.


Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "close an open file by name"
Thread Thread Starter Forum Replies Last Post
Disk util error when tried to open and close an excel file ? Judah Windows Software 3 28-11-2010 05:21 AM
Script to close open files ara Windows Server Help 2 31-08-2010 06:49 PM
How to close an open session cd Anathakrishnan Windows Software 3 26-06-2009 06:24 PM
Script to close open files in file server Gustavo Windows Server Help 2 22-05-2008 07:59 PM
Port 21 (FTP) Open. How to close. Kenyon Windows x64 Edition 2 26-01-2008 12:22 AM


All times are GMT +5.5. The time now is 08:18 AM.