Do anyone know if its possible to detect if the last boot up was preceded by a power-failure in Windows ?
My reason for wanting to detect this is to know when to re-scan files I frequently modify on disk with my service.
If there is a normal startup, I can be quite sure that the shutdown went smooth and the data that was in in-memory file buffers was flushed to disk.
As a simple implementation, would CreateFile with FILE_FLAG_DELETE_ON_CLOSE (immdediately followed by FlushFileBuffers just to be sure) not work?
If the system shuts down cleanly, your application will exit and the file handle will be closed, so the OS will delete the file.
If power fails or the world ends, the OS doesn’t get a chance to close any handles or delete any files. Thus, the file will still be present after the system comes up again.