On 5/1/07, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > After doing some research I found that it seems to be impossible to
> > use CreateFile for a file that doesn't have SHARE_READ. I played with
> > different combinations and with FLAG_BACKUP_SEMANTICS and nothing
> > helped. However on Windows there's still a possibility to read
> > attributes: use FindFirstFile. _WIN32_FIND_DATA structure seems to
> > have all the necessary fields (attributes, file times, size and
> > full/short filename), and FindFirstFile doesn't care about sharing at
> > all...
> So what about GetFileAttributesEx? What are the conditions under which
> I can successfully invoke it?

Seems to have the same problems as with CreateFile(...):

// 1.cc
#include <windows.h>
#include <stdio.h>

int main(int argc, char** argv)
{
        WIN32_FILE_ATTRIBUTE_DATA data;
        if(!GetFileAttributesEx("pagefile.sys", GetFileExInfoStandard, 
(LPVOID)&data))
        {
                char buffer[1024];
                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 
0,
buffer, 1024, NULL);
                printf("Error %d: %s\n", GetLastError(), buffer);
                return 1;
        }
        printf("Success\n");
        return 0;
}

// 2.cc
#include <windows.h>
#include <stdio.h>

int main(int argc, char** argv)
{
        WIN32_FIND_DATA data;
        if(INVALID_HANDLE_VALUE == FindFirstFile("pagefile.sys", &data))
        {
                char buffer[1024];
                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 
0,
buffer, 1024, NULL);
                printf("Error %d: %s\n", GetLastError(), buffer);
                return 1;
        }
        printf("Success\n");
        return 0;
}

C:\>C:\3\1.exe
Error 32: The process cannot access the file because it is being used
by another process.

C:\>C:\3\2.exe
Success
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to