Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using createdirectory API fcn

Posted on 2003-12-09
6
Medium Priority
?
320 Views
Last Modified: 2010-04-05
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

0
Comment
Question by:mem100
5 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 9910718
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:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20166800.html

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 9910747
0
 

Author Comment

by:mem100
ID: 9976111
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
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13056299
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question