Solved

using createdirectory API fcn

Posted on 2003-12-09
6
291 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
6 Comments
 
LVL 8

Expert Comment

by:gmayo
Comment Utility
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
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
Comment Utility
0
 

Author Comment

by:mem100
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now