-
Test a file to see if it's open
I want to act upon files that are created by others _after_ they have closed
the file.
Files are created by an app that allows user saves at will. It is possible
to do one or more interim saves, therefore, before being "finished." Users
save the file across a network to the box were my app resides, so they are
remote but the file is local.
I only want to pick up "finished" (closed) files. I thought I could do it
by using CreateFile, setting the dwShareMode parameter to 0. However, it
doesn't appear to work that way in testing; I can open the file and it still
gets acted upon (even when opening the file locally).
Can anyone suggest a way to test to see if another user/app (across a
network connection) currently has a file open--or the reflexive, test to see
if I have the file (on the local box) open exclusively?
My current call:
hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
OPEN_EXISTING, 0&, 0&)
TIA
John
-
Re: Test a file to see if it's open
You could try renaming it. if it succeds, it is not open, and just rename it
back.
--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer
iCode Systems
"JohnN" <jnielsRe-moveThis@att.net> wrote in message
news:3a777e08@news.devx.com...
> I want to act upon files that are created by others _after_ they have
closed
> the file.
>
> Files are created by an app that allows user saves at will. It is possible
> to do one or more interim saves, therefore, before being "finished." Users
> save the file across a network to the box were my app resides, so they are
> remote but the file is local.
>
> I only want to pick up "finished" (closed) files. I thought I could do it
> by using CreateFile, setting the dwShareMode parameter to 0. However, it
> doesn't appear to work that way in testing; I can open the file and it
still
> gets acted upon (even when opening the file locally).
>
> Can anyone suggest a way to test to see if another user/app (across a
> network connection) currently has a file open--or the reflexive, test to
see
> if I have the file (on the local box) open exclusively?
>
> My current call:
>
> hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> OPEN_EXISTING, 0&, 0&)
>
> TIA
> John
>
>
-
Re: Test a file to see if it's open
(My "reply" didn't post, I must have hit the individual reply by mistake.
Sorry.)
Thanks Dean
I should have reached back to my DOS days and remembered that option. I was
hoping for a programmatic test, but sometimes "'ya gotta do what 'ya gotta
do"
John..
"Dean Earley" <dean.earley@icode.co.uk> wrote in message
news:3a78216b@news.devx.com...
> You could try renaming it. if it succeds, it is not open, and just rename
it
> back.
>
> --
> Dean Earley (dean.earley@icode.co.uk)
> Assistant Developer
>
> iCode Systems
> "JohnN" <jnielsRe-moveThis@att.net> wrote in message
> news:3a777e08@news.devx.com...
> > I want to act upon files that are created by others _after_ they have
> closed
> > the file.
> >
> > Files are created by an app that allows user saves at will. It is
possible
> > to do one or more interim saves, therefore, before being "finished."
Users
> > save the file across a network to the box were my app resides, so they
are
> > remote but the file is local.
> >
> > I only want to pick up "finished" (closed) files. I thought I could do
it
> > by using CreateFile, setting the dwShareMode parameter to 0. However, it
> > doesn't appear to work that way in testing; I can open the file and it
> still
> > gets acted upon (even when opening the file locally).
> >
> > Can anyone suggest a way to test to see if another user/app (across a
> > network connection) currently has a file open--or the reflexive, test to
> see
> > if I have the file (on the local box) open exclusively?
> >
> > My current call:
> >
> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> > OPEN_EXISTING, 0&, 0&)
> >
> > TIA
> > John
> >
> >
>
>
-
Re: Test a file to see if it's open
Try opening the file for random (or binary, I forget) and request a read write
lock on the file. If someone else has the file open, this call will fail
(because of the locking).
I believe this is somewhat of a standard when it comes to file transmissions
between programs.
-- Joel
JohnN wrote:
> I want to act upon files that are created by others _after_ they have closed
> the file.
>
> Files are created by an app that allows user saves at will. It is possible
> to do one or more interim saves, therefore, before being "finished." Users
> save the file across a network to the box were my app resides, so they are
> remote but the file is local.
>
> I only want to pick up "finished" (closed) files. I thought I could do it
> by using CreateFile, setting the dwShareMode parameter to 0. However, it
> doesn't appear to work that way in testing; I can open the file and it still
> gets acted upon (even when opening the file locally).
>
> Can anyone suggest a way to test to see if another user/app (across a
> network connection) currently has a file open--or the reflexive, test to see
> if I have the file (on the local box) open exclusively?
>
> My current call:
>
> hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> OPEN_EXISTING, 0&, 0&)
>
> TIA
> John
-
Re: Test a file to see if it's open
Hi Joel
I tried both the VB call
Open sPath & sFName For Random [Binary] Access Write Lock Write As #1
and API calls
hFile = CreateFile(sPath & sFName, GENERIC_WRITE, _
&H2, 0&, OPEN_EXISTING, 0&, 0&)
I spent some time experimenting. The only way I can get Open/CreateFile to
fail
is if the target file is _previously_ opened exclusive (either a Word/Excel
file--which appears to be their default behavior or an API-created
CreateFile ditty with a share property of &H0 thru 3):
hFile = CreateFile("C:\Temp\Test.txt", GENERIC_READ + GENERIC_WRITE, _
0&, 0&, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0&)
If I open any of the files using a program that does *not* lock exclusive,
it can be read, can be manipulated/deleted, etc., leaving the copy of the
file the app has open to be separately saved (it's completely contained in
memory so it doesn't have to/try to reference the disk file<?>).
As I think about it, today I had the same file open twice in Notepad, ending
up with two versions of the same text file; the last one saved could have
wiped out the first-saved version had I done that.
Unfortunately, the app that is creating the files acts like Notepad and does
not open the file
exclusive, so Open/CreateFile doesn't fail when I read a file it has open:
hFile = CreateFile("C:\Temp\" & sFName, GENERIC_WRITE, _
&H2, 0&, OPEN_EXISTING, 0&, 0&)
Returns a valid handle.
Short of asking the app vendor to rewrite their code to open exclusive
(HA!), are there any other ideas?
Or am I missing something?
Thanks Again
John
"Joel Ryan" <jryan@vsi-hq.com> wrote in message
news:3A79C1D9.F1EBBFAC@vsi-hq.com...
> Try opening the file for random (or binary, I forget) and request a read
write
> lock on the file. If someone else has the file open, this call will fail
> (because of the locking).
>
> I believe this is somewhat of a standard when it comes to file
transmissions
> between programs.
>
> -- Joel
>
> JohnN wrote:
>
> > I want to act upon files that are created by others _after_ they have
closed
> > the file.
> >
> > Files are created by an app that allows user saves at will. It is
possible
> > to do one or more interim saves, therefore, before being "finished."
Users
> > save the file across a network to the box were my app resides, so they
are
> > remote but the file is local.
> >
> > I only want to pick up "finished" (closed) files. I thought I could do
it
> > by using CreateFile, setting the dwShareMode parameter to 0. However, it
> > doesn't appear to work that way in testing; I can open the file and it
still
> > gets acted upon (even when opening the file locally).
> >
> > Can anyone suggest a way to test to see if another user/app (across a
> > network connection) currently has a file open--or the reflexive, test to
see
> > if I have the file (on the local box) open exclusively?
> >
> > My current call:
> >
> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> > OPEN_EXISTING, 0&, 0&)
> >
> > TIA
> > John
>
-
Re: Test a file to see if it's open
"JohnN" <jnielsRe-moveThis@att.net> wrote:
>Hi Joel
>
>I tried both the VB call
> Open sPath & sFName For Random [Binary] Access Write Lock Write As #1
>
>and API calls
> hFile = CreateFile(sPath & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>I spent some time experimenting. The only way I can get Open/CreateFile
to
>fail
>is if the target file is _previously_ opened exclusive (either a Word/Excel
>file--which appears to be their default behavior or an API-created
>CreateFile ditty with a share property of &H0 thru 3):
>
> hFile = CreateFile("C:\Temp\Test.txt", GENERIC_READ + GENERIC_WRITE,
_
> 0&, 0&, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0&)
>
>
>If I open any of the files using a program that does *not* lock exclusive,
>it can be read, can be manipulated/deleted, etc., leaving the copy of the
>file the app has open to be separately saved (it's completely contained
in
>memory so it doesn't have to/try to reference the disk file<?>).
>
>As I think about it, today I had the same file open twice in Notepad, ending
>up with two versions of the same text file; the last one saved could have
>wiped out the first-saved version had I done that.
>
>Unfortunately, the app that is creating the files acts like Notepad and
does
>not open the file
>exclusive, so Open/CreateFile doesn't fail when I read a file it has open:
>
> hFile = CreateFile("C:\Temp\" & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>Returns a valid handle.
>
>Short of asking the app vendor to rewrite their code to open exclusive
>(HA!), are there any other ideas?
>
>Or am I missing something?
>
>Thanks Again
>John
>
>
>
>
>"Joel Ryan" <jryan@vsi-hq.com> wrote in message
>news:3A79C1D9.F1EBBFAC@vsi-hq.com...
>> Try opening the file for random (or binary, I forget) and request a read
>write
>> lock on the file. If someone else has the file open, this call will fail
>> (because of the locking).
>>
>> I believe this is somewhat of a standard when it comes to file
>transmissions
>> between programs.
>>
>> -- Joel
>>
>> JohnN wrote:
>>
>> > I want to act upon files that are created by others _after_ they have
>closed
>> > the file.
>> >
>> > Files are created by an app that allows user saves at will. It is
>possible
>> > to do one or more interim saves, therefore, before being "finished."
>Users
>> > save the file across a network to the box were my app resides, so they
>are
>> > remote but the file is local.
>> >
>> > I only want to pick up "finished" (closed) files. I thought I could
do
>it
>> > by using CreateFile, setting the dwShareMode parameter to 0. However,
it
>> > doesn't appear to work that way in testing; I can open the file and
it
>still
>> > gets acted upon (even when opening the file locally).
>> >
>> > Can anyone suggest a way to test to see if another user/app (across
a
>> > network connection) currently has a file open--or the reflexive, test
to
>see
>> > if I have the file (on the local box) open exclusively?
>> >
>> > My current call:
>> >
>> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
>> > OPEN_EXISTING, 0&, 0&)
>> >
>> > TIA
>> > John
>>
>
>
-
Re: Test a file to see if it's open
Hi ,
Have you tested using LockFileEx(). There is option to lock file exclusively.
If yes , let me know.
"JohnN" <jnielsRe-moveThis@att.net> wrote:
>Hi Joel
>
>I tried both the VB call
> Open sPath & sFName For Random [Binary] Access Write Lock Write As #1
>
>and API calls
> hFile = CreateFile(sPath & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>I spent some time experimenting. The only way I can get Open/CreateFile
to
>fail
>is if the target file is _previously_ opened exclusive (either a Word/Excel
>file--which appears to be their default behavior or an API-created
>CreateFile ditty with a share property of &H0 thru 3):
>
> hFile = CreateFile("C:\Temp\Test.txt", GENERIC_READ + GENERIC_WRITE,
_
> 0&, 0&, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0&)
>
>
>If I open any of the files using a program that does *not* lock exclusive,
>it can be read, can be manipulated/deleted, etc., leaving the copy of the
>file the app has open to be separately saved (it's completely contained
in
>memory so it doesn't have to/try to reference the disk file<?>).
>
>As I think about it, today I had the same file open twice in Notepad, ending
>up with two versions of the same text file; the last one saved could have
>wiped out the first-saved version had I done that.
>
>Unfortunately, the app that is creating the files acts like Notepad and
does
>not open the file
>exclusive, so Open/CreateFile doesn't fail when I read a file it has open:
>
> hFile = CreateFile("C:\Temp\" & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>Returns a valid handle.
>
>Short of asking the app vendor to rewrite their code to open exclusive
>(HA!), are there any other ideas?
>
>Or am I missing something?
>
>Thanks Again
>John
>
>
>
>
>"Joel Ryan" <jryan@vsi-hq.com> wrote in message
>news:3A79C1D9.F1EBBFAC@vsi-hq.com...
>> Try opening the file for random (or binary, I forget) and request a read
>write
>> lock on the file. If someone else has the file open, this call will fail
>> (because of the locking).
>>
>> I believe this is somewhat of a standard when it comes to file
>transmissions
>> between programs.
>>
>> -- Joel
>>
>> JohnN wrote:
>>
>> > I want to act upon files that are created by others _after_ they have
>closed
>> > the file.
>> >
>> > Files are created by an app that allows user saves at will. It is
>possible
>> > to do one or more interim saves, therefore, before being "finished."
>Users
>> > save the file across a network to the box were my app resides, so they
>are
>> > remote but the file is local.
>> >
>> > I only want to pick up "finished" (closed) files. I thought I could
do
>it
>> > by using CreateFile, setting the dwShareMode parameter to 0. However,
it
>> > doesn't appear to work that way in testing; I can open the file and
it
>still
>> > gets acted upon (even when opening the file locally).
>> >
>> > Can anyone suggest a way to test to see if another user/app (across
a
>> > network connection) currently has a file open--or the reflexive, test
to
>see
>> > if I have the file (on the local box) open exclusively?
>> >
>> > My current call:
>> >
>> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
>> > OPEN_EXISTING, 0&, 0&)
>> >
>> > TIA
>> > John
>>
>
>
-
Re: Test a file to see if it's open
You could try renaming it. if it succeds, it is not open, and just rename it
back.
--
Dean Earley (dean.earley@icode.co.uk)
Assistant Developer
iCode Systems
"JohnN" <jnielsRe-moveThis@att.net> wrote in message
news:3a777e08@news.devx.com...
> I want to act upon files that are created by others _after_ they have
closed
> the file.
>
> Files are created by an app that allows user saves at will. It is possible
> to do one or more interim saves, therefore, before being "finished." Users
> save the file across a network to the box were my app resides, so they are
> remote but the file is local.
>
> I only want to pick up "finished" (closed) files. I thought I could do it
> by using CreateFile, setting the dwShareMode parameter to 0. However, it
> doesn't appear to work that way in testing; I can open the file and it
still
> gets acted upon (even when opening the file locally).
>
> Can anyone suggest a way to test to see if another user/app (across a
> network connection) currently has a file open--or the reflexive, test to
see
> if I have the file (on the local box) open exclusively?
>
> My current call:
>
> hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> OPEN_EXISTING, 0&, 0&)
>
> TIA
> John
>
>
-
Re: Test a file to see if it's open
(My "reply" didn't post, I must have hit the individual reply by mistake.
Sorry.)
Thanks Dean
I should have reached back to my DOS days and remembered that option. I was
hoping for a programmatic test, but sometimes "'ya gotta do what 'ya gotta
do"
John..
"Dean Earley" <dean.earley@icode.co.uk> wrote in message
news:3a78216b@news.devx.com...
> You could try renaming it. if it succeds, it is not open, and just rename
it
> back.
>
> --
> Dean Earley (dean.earley@icode.co.uk)
> Assistant Developer
>
> iCode Systems
> "JohnN" <jnielsRe-moveThis@att.net> wrote in message
> news:3a777e08@news.devx.com...
> > I want to act upon files that are created by others _after_ they have
> closed
> > the file.
> >
> > Files are created by an app that allows user saves at will. It is
possible
> > to do one or more interim saves, therefore, before being "finished."
Users
> > save the file across a network to the box were my app resides, so they
are
> > remote but the file is local.
> >
> > I only want to pick up "finished" (closed) files. I thought I could do
it
> > by using CreateFile, setting the dwShareMode parameter to 0. However, it
> > doesn't appear to work that way in testing; I can open the file and it
> still
> > gets acted upon (even when opening the file locally).
> >
> > Can anyone suggest a way to test to see if another user/app (across a
> > network connection) currently has a file open--or the reflexive, test to
> see
> > if I have the file (on the local box) open exclusively?
> >
> > My current call:
> >
> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> > OPEN_EXISTING, 0&, 0&)
> >
> > TIA
> > John
> >
> >
>
>
-
Re: Test a file to see if it's open
Try opening the file for random (or binary, I forget) and request a read write
lock on the file. If someone else has the file open, this call will fail
(because of the locking).
I believe this is somewhat of a standard when it comes to file transmissions
between programs.
-- Joel
JohnN wrote:
> I want to act upon files that are created by others _after_ they have closed
> the file.
>
> Files are created by an app that allows user saves at will. It is possible
> to do one or more interim saves, therefore, before being "finished." Users
> save the file across a network to the box were my app resides, so they are
> remote but the file is local.
>
> I only want to pick up "finished" (closed) files. I thought I could do it
> by using CreateFile, setting the dwShareMode parameter to 0. However, it
> doesn't appear to work that way in testing; I can open the file and it still
> gets acted upon (even when opening the file locally).
>
> Can anyone suggest a way to test to see if another user/app (across a
> network connection) currently has a file open--or the reflexive, test to see
> if I have the file (on the local box) open exclusively?
>
> My current call:
>
> hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> OPEN_EXISTING, 0&, 0&)
>
> TIA
> John
-
Re: Test a file to see if it's open
Hi Joel
I tried both the VB call
Open sPath & sFName For Random [Binary] Access Write Lock Write As #1
and API calls
hFile = CreateFile(sPath & sFName, GENERIC_WRITE, _
&H2, 0&, OPEN_EXISTING, 0&, 0&)
I spent some time experimenting. The only way I can get Open/CreateFile to
fail
is if the target file is _previously_ opened exclusive (either a Word/Excel
file--which appears to be their default behavior or an API-created
CreateFile ditty with a share property of &H0 thru 3):
hFile = CreateFile("C:\Temp\Test.txt", GENERIC_READ + GENERIC_WRITE, _
0&, 0&, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0&)
If I open any of the files using a program that does *not* lock exclusive,
it can be read, can be manipulated/deleted, etc., leaving the copy of the
file the app has open to be separately saved (it's completely contained in
memory so it doesn't have to/try to reference the disk file<?>).
As I think about it, today I had the same file open twice in Notepad, ending
up with two versions of the same text file; the last one saved could have
wiped out the first-saved version had I done that.
Unfortunately, the app that is creating the files acts like Notepad and does
not open the file
exclusive, so Open/CreateFile doesn't fail when I read a file it has open:
hFile = CreateFile("C:\Temp\" & sFName, GENERIC_WRITE, _
&H2, 0&, OPEN_EXISTING, 0&, 0&)
Returns a valid handle.
Short of asking the app vendor to rewrite their code to open exclusive
(HA!), are there any other ideas?
Or am I missing something?
Thanks Again
John
"Joel Ryan" <jryan@vsi-hq.com> wrote in message
news:3A79C1D9.F1EBBFAC@vsi-hq.com...
> Try opening the file for random (or binary, I forget) and request a read
write
> lock on the file. If someone else has the file open, this call will fail
> (because of the locking).
>
> I believe this is somewhat of a standard when it comes to file
transmissions
> between programs.
>
> -- Joel
>
> JohnN wrote:
>
> > I want to act upon files that are created by others _after_ they have
closed
> > the file.
> >
> > Files are created by an app that allows user saves at will. It is
possible
> > to do one or more interim saves, therefore, before being "finished."
Users
> > save the file across a network to the box were my app resides, so they
are
> > remote but the file is local.
> >
> > I only want to pick up "finished" (closed) files. I thought I could do
it
> > by using CreateFile, setting the dwShareMode parameter to 0. However, it
> > doesn't appear to work that way in testing; I can open the file and it
still
> > gets acted upon (even when opening the file locally).
> >
> > Can anyone suggest a way to test to see if another user/app (across a
> > network connection) currently has a file open--or the reflexive, test to
see
> > if I have the file (on the local box) open exclusively?
> >
> > My current call:
> >
> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
> > OPEN_EXISTING, 0&, 0&)
> >
> > TIA
> > John
>
-
Re: Test a file to see if it's open
"JohnN" <jnielsRe-moveThis@att.net> wrote:
>Hi Joel
>
>I tried both the VB call
> Open sPath & sFName For Random [Binary] Access Write Lock Write As #1
>
>and API calls
> hFile = CreateFile(sPath & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>I spent some time experimenting. The only way I can get Open/CreateFile
to
>fail
>is if the target file is _previously_ opened exclusive (either a Word/Excel
>file--which appears to be their default behavior or an API-created
>CreateFile ditty with a share property of &H0 thru 3):
>
> hFile = CreateFile("C:\Temp\Test.txt", GENERIC_READ + GENERIC_WRITE,
_
> 0&, 0&, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0&)
>
>
>If I open any of the files using a program that does *not* lock exclusive,
>it can be read, can be manipulated/deleted, etc., leaving the copy of the
>file the app has open to be separately saved (it's completely contained
in
>memory so it doesn't have to/try to reference the disk file<?>).
>
>As I think about it, today I had the same file open twice in Notepad, ending
>up with two versions of the same text file; the last one saved could have
>wiped out the first-saved version had I done that.
>
>Unfortunately, the app that is creating the files acts like Notepad and
does
>not open the file
>exclusive, so Open/CreateFile doesn't fail when I read a file it has open:
>
> hFile = CreateFile("C:\Temp\" & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>Returns a valid handle.
>
>Short of asking the app vendor to rewrite their code to open exclusive
>(HA!), are there any other ideas?
>
>Or am I missing something?
>
>Thanks Again
>John
>
>
>
>
>"Joel Ryan" <jryan@vsi-hq.com> wrote in message
>news:3A79C1D9.F1EBBFAC@vsi-hq.com...
>> Try opening the file for random (or binary, I forget) and request a read
>write
>> lock on the file. If someone else has the file open, this call will fail
>> (because of the locking).
>>
>> I believe this is somewhat of a standard when it comes to file
>transmissions
>> between programs.
>>
>> -- Joel
>>
>> JohnN wrote:
>>
>> > I want to act upon files that are created by others _after_ they have
>closed
>> > the file.
>> >
>> > Files are created by an app that allows user saves at will. It is
>possible
>> > to do one or more interim saves, therefore, before being "finished."
>Users
>> > save the file across a network to the box were my app resides, so they
>are
>> > remote but the file is local.
>> >
>> > I only want to pick up "finished" (closed) files. I thought I could
do
>it
>> > by using CreateFile, setting the dwShareMode parameter to 0. However,
it
>> > doesn't appear to work that way in testing; I can open the file and
it
>still
>> > gets acted upon (even when opening the file locally).
>> >
>> > Can anyone suggest a way to test to see if another user/app (across
a
>> > network connection) currently has a file open--or the reflexive, test
to
>see
>> > if I have the file (on the local box) open exclusively?
>> >
>> > My current call:
>> >
>> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
>> > OPEN_EXISTING, 0&, 0&)
>> >
>> > TIA
>> > John
>>
>
>
-
Re: Test a file to see if it's open
Hi ,
Have you tested using LockFileEx(). There is option to lock file exclusively.
If yes , let me know.
"JohnN" <jnielsRe-moveThis@att.net> wrote:
>Hi Joel
>
>I tried both the VB call
> Open sPath & sFName For Random [Binary] Access Write Lock Write As #1
>
>and API calls
> hFile = CreateFile(sPath & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>I spent some time experimenting. The only way I can get Open/CreateFile
to
>fail
>is if the target file is _previously_ opened exclusive (either a Word/Excel
>file--which appears to be their default behavior or an API-created
>CreateFile ditty with a share property of &H0 thru 3):
>
> hFile = CreateFile("C:\Temp\Test.txt", GENERIC_READ + GENERIC_WRITE,
_
> 0&, 0&, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH, 0&)
>
>
>If I open any of the files using a program that does *not* lock exclusive,
>it can be read, can be manipulated/deleted, etc., leaving the copy of the
>file the app has open to be separately saved (it's completely contained
in
>memory so it doesn't have to/try to reference the disk file<?>).
>
>As I think about it, today I had the same file open twice in Notepad, ending
>up with two versions of the same text file; the last one saved could have
>wiped out the first-saved version had I done that.
>
>Unfortunately, the app that is creating the files acts like Notepad and
does
>not open the file
>exclusive, so Open/CreateFile doesn't fail when I read a file it has open:
>
> hFile = CreateFile("C:\Temp\" & sFName, GENERIC_WRITE, _
> &H2, 0&, OPEN_EXISTING, 0&, 0&)
>
>Returns a valid handle.
>
>Short of asking the app vendor to rewrite their code to open exclusive
>(HA!), are there any other ideas?
>
>Or am I missing something?
>
>Thanks Again
>John
>
>
>
>
>"Joel Ryan" <jryan@vsi-hq.com> wrote in message
>news:3A79C1D9.F1EBBFAC@vsi-hq.com...
>> Try opening the file for random (or binary, I forget) and request a read
>write
>> lock on the file. If someone else has the file open, this call will fail
>> (because of the locking).
>>
>> I believe this is somewhat of a standard when it comes to file
>transmissions
>> between programs.
>>
>> -- Joel
>>
>> JohnN wrote:
>>
>> > I want to act upon files that are created by others _after_ they have
>closed
>> > the file.
>> >
>> > Files are created by an app that allows user saves at will. It is
>possible
>> > to do one or more interim saves, therefore, before being "finished."
>Users
>> > save the file across a network to the box were my app resides, so they
>are
>> > remote but the file is local.
>> >
>> > I only want to pick up "finished" (closed) files. I thought I could
do
>it
>> > by using CreateFile, setting the dwShareMode parameter to 0. However,
it
>> > doesn't appear to work that way in testing; I can open the file and
it
>still
>> > gets acted upon (even when opening the file locally).
>> >
>> > Can anyone suggest a way to test to see if another user/app (across
a
>> > network connection) currently has a file open--or the reflexive, test
to
>see
>> > if I have the file (on the local box) open exclusively?
>> >
>> > My current call:
>> >
>> > hFile = CreateFile(sFName, GENERIC_READ, 0&, 0&, _
>> > OPEN_EXISTING, 0&, 0&)
>> >
>> > TIA
>> > John
>>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks