Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Jun : rights to read/write a directory in an install

www.cryer.info
Managed Newsgroup Archive

rights to read/write a directory in an install

Subject:rights to read/write a directory in an install
Posted by:"Ed Dressel" (none)
Date:Thu, 31 May 2007 16:34:19

I am creating a sub directory under CSIDL_COMMON_APPDATA and want to set it
so that the user (or all users) have read/write rights to it. I am doing it
in a DLL as Wise Install System 9.02 does not support creating directory
rights.

I can't get it to work--the user 'Everyone' is added (is that a user named
Everyone or is it everyone on the computer?), but they do not have any
rights  to the directory. The return value is 0 (indicating it was a
success--note
that I assigned other values to check that the succss value is returned and
in infact is).

I tried the logged in user ( from the GetUsername function) but when the
install program starts it prompts for the admin password before logging
in --then GetUsername returns the administraors name, not the logged in
user.

How can I set the rights to a CSIDL_COMMON_APPDATA directory so that the
files I install there have read/write

My code is below (I hard coded some info in just testing it)


Ed Dressel

function SetDirectoryRights: Dword;
var
  pDACL: PACL;
  pEA: PEXPLICIT_ACCESS_A;
  R: DWORD;
  lFolder: array[0..1024] of Char;
  lPath: String;
  lPIDL: PItemIDList;
begin
  if SHGetSpecialFolderLocation(0, CSIDL_COMMON_APPDATA,lPIDL) = NOERROR
then
  begin
    SHGetPathFromIDList(lPIDL, lFolder);
    GlobalFreePtr(lPIDL);
    lPath := lFolder + '\Trust Builders\Data';

    pEA := AllocMem(SizeOf(EXPLICIT_ACCESS));
    BuildExplicitAccessWithName(pEA, 'EVERYONE', GENERIC_WRITE or
GENERIC_READ, GRANT_ACCESS, SUB_OBJECTS_ONLY_INHERIT);
    R := SetEntriesInAcl(1, pEA, nil, pDACL);
    if R = ERROR_SUCCESS then
    begin
      if SetNamedSecurityInfo(PChar(lPath), SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION, nil, nil, pDACL, nil) <> ERROR_SUCCESS then
        result := 2
      else
        result := 0;
      LocalFree(Cardinal(pDACL));
    end
    else
      result := 1;
  end
  else
    result := 3;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive