flat assembler
Message board for the users of flat assembler.

Index > Windows > Accessing "in Use" Files == ?

Author
Thread Post new topic Reply to topic
shakuni



Joined: 11 Oct 2007
Posts: 24
shakuni 14 May 2008, 05:53
How can I access the files that are in-use by other processes. Say there is this file called "locked.txt", which is in use by process A. Now how can I copy this file to another location programmatically. Normal methods will fail with the error "The process cannot access the file because it is being used by another process.".

Any ideas ?

_________________
There is no rule, law or tradition that apply universally... including this one.
Post 14 May 2008, 05:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20338
Location: In your JS exploiting you and your system
revolution 14 May 2008, 06:26
It depends on how the file is locked. When Process A opens the file it can say what access it wants to allow other process to have.
Win32 SDK: CreateFile wrote:
dwShareMode

Set of bit flags that specifies how the object can be shared. If dwShareMode is 0, the object cannot be shared. Subsequent open operations on the object will fail, until the handle is closed.
To share the object, use a combination of one or more of the following values:

Value Meaning
FILE_SHARE_DELETE Windows NT only: Subsequent open operations on the object will succeed only if delete access is requested.
FILE_SHARE_READ Subsequent open operations on the object will succeed only if read access is requested.
FILE_SHARE_WRITE Subsequent open operations on the object will succeed only if write access is requested.
There are also some other ways to lock only portions of a shared file, all of these things can prevent you from copying a file when it is locked in certain ways.
Post 14 May 2008, 06:26
View user's profile Send private message Visit poster's website Reply with quote
shakuni



Joined: 11 Oct 2007
Posts: 24
shakuni 14 May 2008, 06:43
Quote:

all of these things can prevent you from copying a file when it is locked in certain ways.

Yes I know that. Now tell me how can I circumvent those locks.
Post 14 May 2008, 06:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20338
Location: In your JS exploiting you and your system
revolution 14 May 2008, 07:57
shakuni wrote:
Yes I know that. Now tell me how can I circumvent those locks.
  • Close the offending process A
  • Write a KMD to read the HDD directly to get the data
  • Rewrite the OS to always allow read access
  • Use another OS that does not have locks (DOS?)
  • Patch the kernel to alter the dwShareMode parameter on the fly when opening
  • Patch process A so that it allows read sharing
  • Or, the easiest, just accept that sometimes a program needs exclusive access to a file to ensure it doesn't crash or generally go stupid
Post 14 May 2008, 07:57
View user's profile Send private message Visit poster's website Reply with quote
MichaelH



Joined: 03 May 2005
Posts: 402
MichaelH 14 May 2008, 21:01
MoveFileEx might be what you're looking for -


http://msdn.microsoft.com/en-us/library/aa365240(VS.85).aspx

Does the URL tag work for this forum. I can never get it to work Sad
Post 14 May 2008, 21:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 14 May 2008, 22:32
It doesn't work when it has some not really special (apart of the real ones) characters, you have to replace "(" and ")" with its hex counterparts and it will work, example: http://msdn.microsoft.com/en-us/library/aa365240%28VS.85%29.aspx MoveFileEx Function
Post 14 May 2008, 22:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.