Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting Locked File
#5
Try to open the file with CreateFile, without sharing flags. If returns -1, call GetLastError. If it returns ERROR_SHARING_VIOLATION or ERROR_USER_MAPPED_FILE, the file is locked. If CreateFile returns not -1, call CloseHandle. All these are Windows API functions, look in MSDN library.

Note that some process may open (lock) the file immediately after your "is file locked" code says that the file is not locked.

Another way - Restart Manager API. But I did not try it. It seems it knows what processes use the file and can restart them. Vista+.


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)