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
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
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
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
Or using Madshi's package ( http://www.madshi.net ):
https://www.experts-exchange.com/questions/11119105/Share-a-folder-under-win98-network.html
https://www.experts-exchange.com/questions/11119105/Share-a-folder-under-win98-network.html
ASKER
found solution.
it requires Win32 headers from www.delphi-jedi.org
procedure TForm1.Button1Click(Sender : TObject);
var
securityAttr:TSecurityAttr ibutes;
lpsecuritydesc:JwaWinNT.PS ecurityDes criptor; // 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_A CCESS;
ea[0].grfInheritance:=SUB_ CONTAINERS _AND_OBJEC TS_INHERIT ;
ea[0].Trustee.TrusteeForm: =TRUSTEE_I S_NAME;
ea[0].Trustee.TrusteeType: =TRUSTEE_I S_USER;
ea[0].Trustee.ptstrName:=' mark-wks\m arkm';
ea[1].grfAccessPermissions := STANDARD_RIGHTS_ALL or SPECIFIC_RIGHTS_ALL;
ea[1].grfAccessMode:=SET_A CCESS;
ea[1].grfInheritance:=SUB_ CONTAINERS _AND_OBJEC TS_INHERIT ;
ea[1].Trustee.TrusteeForm: =TRUSTEE_I S_NAME;
ea[1].Trustee.TrusteeType: =TRUSTEE_I S_GROUP;
ea[1].Trustee.ptstrName:=' Administra tors';
SetEntriesinAclW(2,@ea,nil ,pacl);
lpsecuritydesc:= Allocmem(sizeof(SECURITY_D ESCRIPTOR_ MIN_LENGTH ));
InitializeSecurityDescript or(lpsecur itydesc,SE CURITY_DES CRIPTOR_RE VISION);
SetSecurityDescriptorDacl( lpsecurity desc,true, pacl,false );
FillChar(securityattr,size of(SECURIT Y_ATTRIBUT ES),#0);
securityattr.nLength:=size of(SECURIT Y_ATTRIBUT ES);
securityattr.lpSecurityDes criptor:=l psecurityd esc;
securityattr.bInheritHandl e:=false;
if createdirectory('\\mark-wk s\home\mar km',@secur ityattr) then
showmessage('folder created')
else showmessage('error creating folder');
hope it helps someone
it requires Win32 headers from www.delphi-jedi.org
procedure TForm1.Button1Click(Sender
var
securityAttr:TSecurityAttr
lpsecuritydesc:JwaWinNT.PS
ea:array[0..1] of TExplicitAccessW;
easize:integer;
pacl:JwaWinNT.PACL;// PACL is also defined in windows.pas
begin
ea[0].grfAccessPermissions
ea[0].grfAccessMode:=SET_A
ea[0].grfInheritance:=SUB_
ea[0].Trustee.TrusteeForm:
ea[0].Trustee.TrusteeType:
ea[0].Trustee.ptstrName:='
ea[1].grfAccessPermissions
ea[1].grfAccessMode:=SET_A
ea[1].grfInheritance:=SUB_
ea[1].Trustee.TrusteeForm:
ea[1].Trustee.TrusteeType:
ea[1].Trustee.ptstrName:='
SetEntriesinAclW(2,@ea,nil
lpsecuritydesc:= Allocmem(sizeof(SECURITY_D
InitializeSecurityDescript
SetSecurityDescriptorDacl(
FillChar(securityattr,size
securityattr.nLength:=size
securityattr.lpSecurityDes
securityattr.bInheritHandl
if createdirectory('\\mark-wk
showmessage('folder created')
else showmessage('error creating folder');
hope it helps someone
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://support.microsoft.com/support/kb/articles/Q102/1/02.ASP
http://support.microsoft.com/support/kb/articles/Q218/9/65.ASP
http://msdn.microsoft.com/library/devprods/vs6/visualc/vcsample/vcsmpcacls.htm
And there are previously asked questions:
http://oldlook.experts-exchange.com/questions/10180694/SetFileSecurity.html
http://oldlook.experts-exchange.com/questions/11170411/File-Permissions-Example.html
http://oldlook.experts-exchange.com/questions/20066615/getting-owner-of-a-file-under-Windows-NT-2000-and-changing-file-attributes.html
Geoff M.