我的Qt / C ++ / Windows程序需要能够在不调用UAC的情况下删除一些文件。
所以,我正在检查文件是否可以在没有UAC的情况下编写,并且令人惊讶的是(在Linux上不是这种情况),如下所示:
if (QFileInfo(targetPath + "/" + applicationFileName).isWritable()
&& QFileInfo(targetPath + "/").isWritable()) {
在没有UAC验证的情况下运行时返回true,但是它仍然失败,并且Process Monitor声称:
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
以管理员身份调用时,它可以完美运行..
有什么想法吗?
答案 0 :(得分:2)
根据QFileInfo documentation,默认情况下不会在Windows上检查权限,您可以使用以下命令启用/禁用检查:
qt_ntfs_permission_lookup++; // turn checking on
bool isWritable = QFileInfo(targetPath + "/" + applicationFileName).isWritable()
&& QFileInfo(targetPath + "/").isWritable();
qt_ntfs_permission_lookup--; // turn it off again