1

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).

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)?

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
Mustafa Magdy
  • 1,230
  • 5
  • 28
  • 44
  • Did you try Boost::fileSystem libraries? – Yahor10 Nov 16 '11 at 09:38
  • Are you really dealing with the case where the software is being *installed* by a non-administrator? This probably can't be done, because if the user doesn't have access to modify the db folder you probably won't be able to change the permissions either. Where is the database folder located? – Harry Johnston Nov 16 '11 at 20:45
  • @Harry, no actually the user install it using "run as administrator", but this is not give him (the normal user) any permission on the db folder by default. – Mustafa Magdy Nov 16 '11 at 22:40
  • In that case Bojan's answer should do the trick. – Harry Johnston Nov 17 '11 at 01:14

2 Answers2

2

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.

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);
Bojan Komazec
  • 9,216
  • 2
  • 41
  • 51
0

This question might help you for C++. This one explains that this is not possible in Java until Java 7. For a more detailed answer, please ask a more specific question (what have you tried so far, why doesn't it work).

Community
  • 1
  • 1
Björn Pollex
  • 75,346
  • 28
  • 201
  • 283