使用普通 c++ 或 java 设置文件夹权限 [英] Set folder permission using plain c++, or java

查看:30
本文介绍了使用普通 c++ 或 java 设置文件夹权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在维护一个使用 J2SE 开发的软件,(但我是 c# 开发人员,实际上在 Java 方面没有丰富的经验).该软件使用 access 作为数据存储,该 access 数据库存储在 db 文件夹中.当用户从标准用户"而不是管理员安装此应用程序时,在 Windows 7 或 Vista 中,他无法获得 db 文件夹的权限.为了使软件运行,我们需要为当前用户(即标准用户)添加修改"权限.

I'm maintaining a software developed using J2SE, (but i'm c# developer actually not have big experience in Java). This software uses access as datastore, this access database is stored on db folder. When the user install this application from "Standard User", not administrator, in Windows 7 or Vista, he cannot get permission on db folder. To make the software run, we need to add "Modify" permission for the current user (which is Standard User).

实际上我搜索了如何使用 Java 来做到这一点,但一无所获,但我发现的资源很少,但还不够.问题是如何向当前登录的用户授予‘修改’权限,无论是在 c++(旧 c++ 不是 .net)中还是使用 Java)?

Actually I searched to how to do that using Java, but found nothing, but i found little resources, but not enough. The question is "How can I grant 'Modify' Permission to the current logged user, in either c++ (old c++ not .net) or using Java)?

推荐答案

MSDN 文章中介绍的功能 "在 C++ 中修改对象的 ACL" 可以完成这项工作.GetNamedSecurityInfo 检索自由裁量权对象的访问控制列表 (DACL)(在您的情况下是目录).SetEntriesInAcl 创建新的访问控制列表 (ACL) 通过将新条目(包括权限)与现有条目合并.SetNamedSecurityInfo 分配修改DACL 返回对象.

Function presented in MSDN article "Modifying the ACLs of an Object in C++" does the job. GetNamedSecurityInfo retrieves discretionary access control list (DACL) for the object (directory in your case). SetEntriesInAcl creates new access control list (ACL) by merging new entries (including permissions) with existing ones. SetNamedSecurityInfo assigns modified DACL back to the object.

关于修改权限是以下权限的组合:FILE_GENERIC_READ |FILE_GENERIC_WRITE |FILE_GENERIC_EXECUTE |DELETE 你可以像这样调用这个函数:

Regarding that Modify permission is a combination of following rights: FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE you can call this function like here:

std::string strFullPath("C:\test");

DWORD dwRes = AddAceToObjectsSecurityDescriptor(
    const_cast<LPTSTR>(strFullPath.c_str()),
    SE_FILE_OBJECT,
    "StandardUser",
    TRUSTEE_IS_NAME,
    FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE,
    GRANT_ACCESS,
    NO_INHERITANCE);

这篇关于使用普通 c++ 或 java 设置文件夹权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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