【问题标题】:How to check if a file can be deleted with current credentials (UAC) (windows, qt)如何检查是否可以使用当前凭据(UAC)删除文件(windows,qt)
【发布时间】:2012-05-10 10:21:35
【问题描述】:

如果可能,我的 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

当以管理员身份调用时,它可以完美运行..

有什么想法吗?

【问题讨论】:

标签: windows qt filesystems


【解决方案1】:

根据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

【讨论】:

  • 这是一个有用的提示,但不幸的是并没有解决这个问题 - windows 仍然会欺骗应用程序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-25
相关资源
最近更新 更多