Need to know if a directory has write permission or not in C++

前端 未结 2 1361
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 13:31

I need to know if a specified directory (local or shared path with login credentials) has write permissions or not.

I am using GetFileAttributes but it always return

相关标签:
2条回答
  • 2020-12-22 13:51

    You would need to replicate the security checking that Windows performs. The AccessCheck function will help that. You are currently well wide of the mark in looking at the file attributes. Windows security is so much more complicated than that.

    Although you said you did not want to do it, the right solution is not to try to check. Simply do whatever it is you are attempting to do. If the system decides that the user does not have sufficient rights, then CreateFile will fail, and the last error will be set to ERROR_ACCESS_DENIED. There's no need for temporary files. You just try to do whatever it is you are doing, and let it fail. You have to handle failure anyway since there are many ways for a file operation to fail, not just security.

    As the saying goes, it is better to ask forgiveness than permission.

    0 讨论(0)
  • 2020-12-22 14:17

    I think you are looking for AccessCheck. FYI, this is not a C++ question, but a Windows API question.

    0 讨论(0)
提交回复
热议问题