Change security settings of an directory

Vincentg
Vincentg used Ask the Experts™
on
Hi all,

Is it possible to change the security settings of an Windows NT4/5 directory with delphi code?
I would like to be able to add a user and change the permissions of this user.
It's no problem if i need te be administrator
on that server.
Please help me with some sample code.

Thanx,
Vincent
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
It's possible, but hard to do this with pure win32 APIs. Perhaps you want to have a look at my package "madSecurity", which is free for non-commercial usage (only). Here's the online documentation:

http://help.madshi.net/madSecurity.htm

Regards, Madshi.

Author

Commented:
Hi Madshi,

I tried to install your component to see if it's of any use for me but it gives an install error.

"One or more lines were too long and have been truncated"
and then "[Fatal Error] madcollection.dpk(31): Read error on 'c:\program files\madcollection\madsecurity\delphi 4\madSecurity.dcu'"

I installed madSecurity from madCollection.exe

Vincent

Commented:
There is no madCollection.dpk! Did you write one yourself or what?

You don't need to do such a thing, you don't need to compile/recompile anything, just run the installer, that's it. The installer already installs all mad* component with precompiled files.

After you've run madCollection.exe just add "madSecurity" to your unit's uses clause and use it. Delphi will automatically find the unit.

Or did the errors occur while running madCollection.exe?

Regards, Madshi.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
Okay, it works.. :)

Can you please give me some code on how to:
1. add a user
2. give this user read/write/full rights to a specific directory. (Rights also apply on sub-directories)

If possible with your component.
3. Remove user from specific directory.
4. Remove user from windows.

Thanks a lot,
Vincent

Commented:
Why don't you look at the documentation?

// give a user read access to a specific directory
FileSecurity('c:\testdir').DAcl.SetFileAccess(Account('SomeUser'), false);

// give a user read access to a specific directory
FileSecurity('c:\testdir').DAcl.SetFileAccess(Account('SomeUser'), true);

// remove user from specific directory
FileSecurity('c:\testdir').DAcl.DeleteItems(Account('SomeUser'));

madSecurity doesn't contain functions to add/delete users. Look at NetUserAdd/NetUserDel, that's not too difficult.

Regards, Madshi.

Commented:
The second example was for *write* access.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial