I have an application that needs to monitor the main disk for file changes through ReadDirectoryChangesW. However, when UAC is turned on, it does not work.
All Windows API calls succeed, but I am not notified of any changes.
I can get around this by individually controlling each directory in the root, but this is a problem because it can lead to a blue screen if there are too many directories.
Is there an acceptable way to bypass UAC and receive file change notifications on the entire main drive?
Relevant CreateFileand ReadDirectoryChangesWgiven below. In case it does not work directory- C: \. If I control any secondary drive (i.e. E: \, F: \, G: \), it works as expected. None of the calls return errors.
HANDLE fileHandle = CreateFileW(directory.c_str(), FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL);
BOOL success = ReadDirectoryChangesW(fileHandle, watched.buffer.data(),
watched.buffer.size(), TRUE,
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE,
NULL, &watched.overlapped, NULL);
Interestingly, .NET System.IO.FileSystemWatcher works , and it uses the same functions and parameters as I do, but it behaves correctly.