Folder permissions VB 2005

P

philg1984

Hi, I am trying to create a named folder using VB2005 and then set
permissions for this folder for a new user i want to create using just code.
I have searched and not found any code which works. Any ideas? Thanks
 
H

Henning Krause [MVP]

Hello Phil,

what exactly do you want to do?
1. Create a folder
2. Set permission on that folder
3. Create a new user?
4. Set permission on the folder for the newly created user?

Greetings,
Henning
 
P

philg1984

Thats right. Thanks.

Henning Krause said:
Hello Phil,

what exactly do you want to do?
1. Create a folder
2. Set permission on that folder
3. Create a new user?
4. Set permission on the folder for the newly created user?

Greetings,
Henning
 
H

Henning Krause [MVP]

Hello,

the correct order would be this:

1. Create the new user
2. Prepare a DirectorySecurity and populate it with the necessary entries
3. Call Directory.CreateDirectory(directory, security) to create the
directory with the security settings.

The first step is the tricky one and depends whether you want to create a
local user or a user in Actice Directory.
To create a local user, see
http://support.microsoft.com/default.aspx?scid=kb;en-us;306271
To create a user in AD, see
http://www.irishdev.com/blogs/jbrennan/archive/2005/02/01/455.aspx.

Once created you can use the NtAccount class to create your
DirectorySecurity:
NTAccount account = new NtAccount(username);
DirectorySecurity sec = new DirectorySecurity();
sec.SetAccessRule(new FileSystemRule(account, FileSystemRights.Read,
AccessControlType.Allow));
// Set the other necessary access rules

Directory.CreateDirectory(name, sec);

Greetings,
Henning Krause
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top