My Qt/C++/Windows program needs to be able to delete some files, if possible, without invoking UAC.
So, I’m checking whether the file can be written without UAC, and surprisingly enough (it’s not the case on Linux), the following line:
if (QFileInfo(targetPath + "/" + applicationFileName).isWritable()
&& QFileInfo(targetPath + "/").isWritable()) {
returns true when run without UAC validation, but.. it still fails, and the Process Monitor claims:
Date & Time: 5/9/2012 9:09:16 AM
Event Class: File System
Operation: CreateFile
Result: ACCESS DENIED
Path: C:\Program Files (x86)\MyApp\MyApp.exe
TID: 4540
Duration: 0.0000278
Desired Access: Delete
Disposition: Open
Options: Non-Directory File, Open Reparse Point
Attributes: n/a
ShareMode: Read, Write, Delete
AllocationSize: n/a
When invoked as Administrator, it works flawlessly..
Any ideas?
According to QFileInfo documentation, the permissions aren’t checked by default on Windows and you can enable/disable the checking with: