1. Readonly:
DWORD attr = GetFileAttributes(PathName);
attr &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributes(PathName, attr );
DeleteFile( PathName );
2. With used files, it is not so easy. You can try to use UnmapViewOfFile() and UnlockFile(), but it works not allways. There are three ways: terminate the program which uses the file, delete it by next reboot or play with assembler codes - look for old samples with assembler.