Link to home
Start Free TrialLog in
Avatar of mem100
mem100

asked on

using createdirectory API fcn

I want to be able to create users home directories on a sever from an application.

Given the username the app should create the home folder using the username as the folder name.the folder should have the following perms

1)administrators-FC
2) username-FC
3) folder should not inherit perms from parent folder

Avatar of geobul
geobul

Hi,

For creating the directory use ForceDirectories function from FileCtrl unit.

For sharing it and giving premissions you'll need NetShareAdd and NetShareSetInfo API functions. Look at this question:
https://www.experts-exchange.com/questions/20166800/detecting-all-shares.html

Regards, Geo
Avatar of mem100

ASKER

found solution.

 it requires  Win32 headers from www.delphi-jedi.org

procedure TForm1.Button1Click(Sender: TObject);
var
    securityAttr:TSecurityAttributes;
    lpsecuritydesc:JwaWinNT.PSecurityDescriptor; // PSecurityDescriptor is also defined in windows.pas
    ea:array[0..1] of TExplicitAccessW;
    easize:integer;
    pacl:JwaWinNT.PACL;// PACL is also defined in windows.pas

begin

ea[0].grfAccessPermissions:= STANDARD_RIGHTS_ALL or SPECIFIC_RIGHTS_ALL;
ea[0].grfAccessMode:=SET_ACCESS;
ea[0].grfInheritance:=SUB_CONTAINERS_AND_OBJECTS_INHERIT;
ea[0].Trustee.TrusteeForm:=TRUSTEE_IS_NAME;
ea[0].Trustee.TrusteeType:=TRUSTEE_IS_USER;
ea[0].Trustee.ptstrName:='mark-wks\markm';

ea[1].grfAccessPermissions:= STANDARD_RIGHTS_ALL or SPECIFIC_RIGHTS_ALL;
ea[1].grfAccessMode:=SET_ACCESS;
ea[1].grfInheritance:=SUB_CONTAINERS_AND_OBJECTS_INHERIT;
ea[1].Trustee.TrusteeForm:=TRUSTEE_IS_NAME;
ea[1].Trustee.TrusteeType:=TRUSTEE_IS_GROUP;
ea[1].Trustee.ptstrName:='Administrators';

SetEntriesinAclW(2,@ea,nil,pacl);

lpsecuritydesc:= Allocmem(sizeof(SECURITY_DESCRIPTOR_MIN_LENGTH));
InitializeSecurityDescriptor(lpsecuritydesc,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(lpsecuritydesc,true,pacl,false);

FillChar(securityattr,sizeof(SECURITY_ATTRIBUTES),#0);
securityattr.nLength:=sizeof(SECURITY_ATTRIBUTES);
securityattr.lpSecurityDescriptor:=lpsecuritydesc;
securityattr.bInheritHandle:=false;

if createdirectory('\\mark-wks\home\markm',@securityattr) then
 showmessage('folder created')
else showmessage('error creating folder');

hope it helps someone
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial