Closing Opened Files

G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

Hi people,

I have an automatic process which runs every day at 6:00 PM on several files
of my computer. The success of this process depends on the availability of
these files: they should not be in a opened state while the process begins.

I know that NET FILE command lists all the opened files on my PC an the ids
of these "processes". I can use NET FILE ID /CLOSE to close that open session
with my files, but this is a manual procedure.

I need to automate this procedure: close all the sessions which have my
files opened, through a script.

Can anyone give me any help how to accomplish this?

Thanks a lot
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

From a command prompt;
net sess /d /y

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Gabriel Giraldo" wrote:
| Hi people,
|
| I have an automatic process which runs every day at 6:00 PM on several
files
| of my computer. The success of this process depends on the availability of
| these files: they should not be in a opened state while the process
begins.
|
| I know that NET FILE command lists all the opened files on my PC an the
ids
| of these "processes". I can use NET FILE ID /CLOSE to close that open
session
| with my files, but this is a manual procedure.
|
| I need to automate this procedure: close all the sessions which have my
| files opened, through a script.
|
| Can anyone give me any help how to accomplish this?
|
| Thanks a lot
|
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.general (More info?)

Hello Gabriel,
If you have Python installed (www.python.org) , the following script works
on my machine. This script assumes that a file id is not more than 4 digits
long. Let me know if you have questions.
Louis

-----begin script-----
import os
filelist=["yourfilenamesgohere", "andhere", "andhere", "etc"]
openfiles=os.popen('net file')
for lines in openfiles:
for files in filelist:
if files in lines:
fileid=int(lines[:5])
command='net file ' + str(fileid) + ' /close'
os.popen(command)
-----end script-----

"Gabriel Giraldo" <GabrielGiraldo@discussions.microsoft.com> wrote in
message news:DD61A519-EDA4-4A6D-B1CA-C03BDABB0035@microsoft.com...
> Hi people,
>
> I have an automatic process which runs every day at 6:00 PM on several
files
> of my computer. The success of this process depends on the availability of
> these files: they should not be in a opened state while the process
begins.
>
> I know that NET FILE command lists all the opened files on my PC an the
ids
> of these "processes". I can use NET FILE ID /CLOSE to close that open
session
> with my files, but this is a manual procedure.
>
> I need to automate this procedure: close all the sessions which have my
> files opened, through a script.
>
> Can anyone give me any help how to accomplish this?
>
> Thanks a lot
>