如何检查目录是否可写在win32 C / winapi? [英] how to check if a directory is writeable in win32 C/winapi?

查看:185
本文介绍了如何检查目录是否可写在win32 C / winapi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道两种不可靠的方法:




  • _access() - 不适用于目录

  • CreateFile() - 在存在虚拟商店(AFAIK)时产生误报。



<最有用的是代码示例,因为win32 ACL访问功能非常复杂。请不要发布链接到msdn,我一直在那里,不能为我的生活弄清楚我应该对所有DACL,SACL和安全描述符 - 我在一个跨平台应用程序这需要这个特定的功能,但在其他方面是平台无关。



编辑:您可以放心地假设在应用程序运行时目录权限不会改变。

解决方案

,您可以在清单文件中禁用位置虚拟化http://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/article.php/c15455/ ) - 这应该使 CreateFile 足够可靠为您的目的。


I know of two methods which are not reliable:

  • _access() - doesn't work on directories (only checks existence)
  • CreateFile() - gives false positives in the presence of virtual store (AFAIK)

Most useful would be a code sample, because the win32 ACL access functions are extremely complicated. Please don't post links to msdn, I've been there and can't for the life of me figure out what I'm supposed to do with all those DACLs, SACLs and security descriptors - I work on a cross-platform app which needs this particular piece of functionality, but otherwise is platform-agnostic. Solutions simpler than accessing Windows ACLs more than welcome.

Edit: you can safely assume that directory permissions won't change while the app is running.

解决方案

you can disable location virtualization for your application in a manifest file (http://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/article.php/c15455/) - this should make CreateFile reliable enough for your purposes.

这篇关于如何检查目录是否可写在win32 C / winapi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆