riv
riv

Reputation: 7323

GetFileAttributes on (locked) system file

Calling GetFileAttributes for a file such as C:/pagefile.sys returns INVALID_FILE_ATTRIBUTES, and GetLastError returns ERROR_SHARING_VIOLATION. Yet it should definitely be possible to retrieve information about system files - e.g. being able to tell if it is a file or a directory. Is there a workaround?

Upvotes: 4

Views: 805

Answers (1)

Mustafa Chelik
Mustafa Chelik

Reputation: 2184

Using FindFirstFile you can get information of pagefile.sys file. You can get the file's other information from ffd.

WIN32_FIND_DATA ffd;    
HANDLE hFind = FindFirstFile( "C:\\pagefile.sys", &ffd );

if ( INVALID_HANDLE_VALUE == hFind )
{
    return 0;
}

if ( !( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
    _int64 filesize = ffd.nFileSizeHigh;
    filesize <<= 32;
    filesize |= ffd.nFileSizeLow;
    printf( "%s is %I64u bytes", ffd.cFileName, filesize );
}

FindClose( hFind );

Upvotes: 2

Related Questions