Open a locked file

Just starting out? Need help? Post your questions and find answers here.
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Open a locked file

Post by RJP Computing »

How can I open a locked file? I know that it will have to be read-only but I really have a use for this.

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Re: Open a locked file

Post by Doobrey »

RJP Computing wrote:How can I open a locked file? I know that it will have to be read-only but I really have a use for this.
You`ll only be able to open it "read only" if the app that locked the file has opened it with read sharing, if the app opened it with exclusive access then there`s nothing you can do until the file is closed..

You`ll have to use the Win32API to try and read it. I tried myself using PB`s ReadFile()..but even though the file was readable, it failed :(

Use OpenFile_() , if that returns OK then use ReadFile_() to access the file
Have a look in API-Guide for the parameters and structures..it`s too hot here, both my braincells have fried and I can`t remember ! :oops:
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Fred and others,
Is this a bug. Shouldn't I be able to open a locked file with the 'OpenFile' and 'ReadFile' commands. I think this should work. Of corse keeping in mind that the file isn't opened with exclusive access.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

IIRC, it is possible with Powerbasic with the 'Shared' keyword : something like OPEN sFile FOR BINARY ACCESS READ SHARED AS #hFile ?

Should be possible with some of the OF_SHARE.. flags if Openfile() would accept flags ?

It also depends on how the file is locked : write, read, read+write, etc...
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Fred can you verify why these function won't open locked files. I need this feature bad

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

I have verified that the file I am tring can be opened with notepad so the application that has it open does NOT have exclusive access to it.

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
Post Reply