I want to use it during uninstall procedure to warn the user ahead. The procedure should work for W2000+, hence Vista API s are not allowed.
似乎可以解决一些冲突:
if( GetFileAttributes( lpPath ) == INVALID_FILE_ATTRIBUTES )
{
// File does not exist
}
else
{
BOOL bCanDelete = FALSE ;
HANDLE hFile = CreateFile( path,
GENERIC_WRITE /*|DELETE*/,
0 /*FILE_SHARE_DELETE*/,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if( hFile != INVALID_HANDLE_VALUE )
{
DWORD size = 10000 ; // a number > file size allowed
if( size != INVALID_FILE_SIZE )
{
if( LockFile( hFile, 0,0, size,0) )
{
UnlockFile( hFile, 0,0, size,0) ;
bCanDelete = TRUE ;
}
}
CloseHandle( hFile ) ;
}
}
Namely it detects these situations: a) Deleting running exe file b) Deleting opened pdf
Using GENERIC_WRITE|DELETE seems to behave similarly. Using DELETE alone works for the case b), but not for a).
我没有积极证据表明,洛克菲利(洛克菲)会迎合任何有意义的冲突,但认为确实如此。
没有人有更好的想法?