The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: shakuni on May 14, 2008, 05:46:19 AM

Title: Accessing "in Use" Files == ?
Post by: shakuni on May 14, 2008, 05:46:19 AM
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 ?
Title: Re: Accessing "in Use" Files == ?
Post by: ecube on May 14, 2008, 05:50:44 AM
look on the forum, hutch posted code to do this.
Title: Re: Accessing "in Use" Files == ?
Post by: shakuni on May 14, 2008, 06:48:06 AM
Quotelook on the forum, hutch posted code to do this.
Can't find it.
Title: Re: Accessing "in Use" Files == ?
Post by: hutch-- on May 14, 2008, 09:28:54 AM
shakuni,

For non-system files such as log files that are repeatedly being written to this method works OK in many instances but it will not open specialised system files.


          invoke CreateFile,OFFSET logbuffer,GENERIC_READ,
                            FILE_SHARE_WRITE or FILE_SHARE_READ,
                            NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL or \
                            FILE_FLAG_POSIX_SEMANTICS,NULL
          mov hFile, eax


The action is with the "FILE_FLAG_POSIX_SEMANTICS" flag as it changes the file access rules to asically Unix rules.
Title: Re: Accessing "in Use" Files == ?
Post by: jj2007 on May 14, 2008, 01:38:06 PM
Try also if there is a diff between using and not using FILE_SHARE_WRITE. Normally you would not need write access.

Attention FILE_FLAG_POSIX_SEMANTICS makes file names case-sensitive.

I assume you have tested a simple CopyFileA?
Title: Re: Accessing "in Use" Files == ?
Post by: Grincheux on June 03, 2008, 07:25:19 PM
You could be interested with the following link : http://technet.microsoft.com/en-us/sysinternals/default.aspx?PHPSESSID=9692e6

Perhaps you saw it...