المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Testing File Access Rights in MFC



C++ Programming
02-19-2010, 06:51 PM
In a program I develop I need to find out if I can have write rights to a given file. Earlier I have used
// Get file attributes
dwAttributes = ::GetFileAttributes(sFileName);
if( dwAttributes != INVALID_FILE_ATTRIBUTES )
{
// If read-only
if( dwAttributes & FILE_ATTRIBUTE_READONLY )
{
bReadOnly = true;
}
}
It has worked well, but with Windows 7 files in some directories, for instance C:\Program Files the files can't be written even if they haven't got the read only flag set. I found Testing File Access Rights in .NET 2.0 (http://www.codeproject.com/KB/files/UserFileAccessRights.aspx)[^ (http://www.codeproject.com/KB/files/UserFileAccessRights.aspx)], but that's .net so it's not useful for me.