不让别人访问目录

席戛戛 2014-03-14 02:27:30
我的程序里面生成了一个临时目录,我不想让别人(程序)访问该目录,但是本程序可以操作该目录及其子目录中的文件。

ps:使用c++
...全文
139 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
席戛戛 2014-03-18
  • 打赏
  • 举报
回复
直接用createfile ,只允许单个打开文件: 第三个参数0表示,当前打开时,其他人打开不了。 itemdata->m_hFile = CreateFile(strNodeDir.t_str(), // lpFileName STANDARD_RIGHTS_ALL, // dwDesiredAccess 0, // dwShareMode NULL, // lpSecurityAttributes OPEN_EXISTING, // dwCreationDisposition FILE_FLAG_BACKUP_SEMANTICS, // dwFlagsAndAttributes NULL ); 不过最后要CloseHandle(itemdata->m_hFile)
mujiok2003 2014-03-14
  • 打赏
  • 举报
回复
文件,目录的权限一般都是基于基于用户和用户组的, 没有基于程序和进程的。
赵4老师 2014-03-14
  • 打赏
  • 举报
回复
C:\WINDOWS\system32>cacls /? 显示或者修改文件的访问控制列表(ACL) CACLS filename [/T] [/M] [/S[:SDDL]] [/E] [/C] [/G user:perm] [/R user [...]] [/P user:perm [...]] [/D user [...]] filename Displays ACLs. /T 更改当前目录及其所有子目录中指定 文件的 ACL。 /M 将装入卷的 ACL 更改到目录。 /S 显示 DACL 的 SDDL 字符串。 /S:SDDL 用 SDDL 字符串中指定的 ACL 替换 (与 /E、/G、/R、/P 或 /D 一起使用时无效)。 /E 编辑 ACL 而不替换。 /C 在出现拒绝访问错误时继续。 /G user:perm 赋予指定用户访问权限。 Perm 可以是: R 读取 W 写入 C 更改(写入) F 完全控制 /R user 撤销指定用户的访问权限(仅在与 /E 一起使用时合法)。 /P user:perm 替换指定用户的访问权限。 Perm 可以是: N 无 R 读取 W 写入 C 更改(写入) F 完全控制 /D user 拒绝指定用户的访问。 在命令中可以使用通配符指定多个文件。也可以在命令中指定 多个用户。 缩写: CI - 容器继承。 ACE 会由目录继承。 OI - 对象继承。 ACE 会由文件继承。 IO - 只继承。 ACE 不适用于当前文件/目录。
u012997273 2014-03-14
  • 打赏
  • 举报
回复
文件系统过滤,轻松搞定,不过略显大材小用了
赵4老师 2014-03-14
  • 打赏
  • 举报
回复
CreateDirectoryEx The CreateDirectoryEx function creates a new directory with a specified path that retains the attributes of a specified template directory. If the underlying file system supports security on files and directories, the function applies a specified security descriptor to the new directory. The new directory retains the other attributes of the specified template directory. Note that CreateDirectoryEx has a template parameter, while CreateDirectory does not. BOOL CreateDirectoryEx( LPCTSTR lpTemplateDirectory, // pointer to template directory path LPCTSTR lpNewDirectory, // pointer to path of directory to create LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to security descriptor ); Parameters lpTemplateDirectory Pointer to a null-terminated string that specifies the path of the directory to use as a template when creating the new directory. lpNewDirectory Pointer to a null-terminated string that specifies the path of the directory to be created. lpSecurityAttributes Windows NT: Pointer to a SECURITY_ATTRIBUTES structure. The lpSecurityDescriptor member of the structure specifies a security descriptor for the new directory. If lpSecurityAttributes is NULL, the directory gets a default security descriptor. The target file system must support security on files and directories for this parameter to have an effect. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks The CreateDirectoryEx function allows you to create directories that inherit stream information from other directories. This function is useful, for example, when dealing with Macintosh directories, which have a resource stream that is needed to properly identify directory contents as an attribute. Some file systems, such as NTFS, support compression or encryption for individual files and directories. On volumes formatted for such a file system, a new directory inherits the compression and encryption attributes of its parent directory. Windows NT: You can obtain a handle to a directory by calling the CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag set. See CreateFile for a code example. QuickInfo Windows NT: Requires version 3.5 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also File I/O Overview, File Functions, CreateDirectory, CreateFile, RemoveDirectory, SECURITY_ATTRIBUTES SECURITY_DESCRIPTOR The SECURITY_DESCRIPTOR structure contains the security information associated with an object. Applications use this structure to set and query an object's security status. Applications are not to modify the SECURITY_DESCRIPTOR structure directly. For creating and manipulating a security descriptor, use the functions listed in the See Also section. typedef PVOID PSECURITY_DESCRIPTOR; Remarks A security descriptor includes information that specifies the following components of an object's security: An owner (SID) A primary group (SID) A discretionary ACL A system ACL Qualifiers for the preceding items Security descriptors use access-control lists (ACLs) and security identifiers (SIDs) to specify the information in this list. A security descriptor can be in absolute or self-relative form. In self-relative form, all members of the structure are located contiguously in memory. In absolute form, the structure only contains pointers to the members. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Unsupported. Windows CE: Unsupported. Header: Declared in winnt.h. See Also Access Control Overview, Access Control Structures, GetSecurityDescriptorControl, GetSecurityDescriptorDacl, GetSecurityDescriptorGroup, GetSecurityDescriptorLength, GetSecurityDescriptorOwner, GetSecurityDescriptorSacl, InitializeSecurityDescriptor, IsValidSecurityDescriptor, SetSecurityDescriptorDacl, SetSecurityDescriptorGroup, SetSecurityDescriptorOwner, SetSecurityDescriptorSacl ……
席戛戛 2014-03-14
  • 打赏
  • 举报
回复
这个是锁文件的吧,?锁目录呢?
赵4老师 2014-03-14
  • 打赏
  • 举报
回复
LockFIle LockFileEx ?

64,666

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧