Folder Permissions c#

Hi, I've got some code to change the folder permissions.
The code will add the user, but when I check the permissions they haven't changed.
The following is the code.
Can anyone help, thanks.
P.S.
I had to add the references System.Management and System.Management.Instrumentation from .NET controls.
I got the code from http://www.redmondpie.com/applying-permissions-on-any-windows-folder-using-c/ 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

   using System.IO;

   using System.Security.AccessControl;

   using System.Management;

  using System.Management.Instrumentation;
namespace Permissions
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


              GetUsers();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void SelectDirectorybtn_Click(object sender, EventArgs e)

     {

                // creating a new instance fot FolderBrowsingDialog 

                                    //to provide user capability to select target Folder

                FolderBrowserDialog myFolderBrowserDialog = new FolderBrowserDialog();

      

                // showing dialog

                myFolderBrowserDialog.ShowDialog();

      

                // Show the path of selected directory in our text Box 

               textBox1.Text = myFolderBrowserDialog.SelectedPath.ToString();

    }
        //http://www.redmondpie.com/applying-permissions-on-any-windows-folder-using-c/
           private void Permissionbtn_Click(object sender, EventArgs e)

    {


    }
       public void GetUsers()

     {

             // This query will query for all user account names in our current Domain

             SelectQuery sQuery = new SelectQuery("Win32_UserAccount", "Domain='" 

                             + System.Environment.UserDomainName.ToString() + "'");

      

              try

              {

                        // Searching for available Users

                         ManagementObjectSearcher mSearcher = new 

                                                        ManagementObjectSearcher(sQuery);

     

                        foreach (ManagementObject mObject in mSearcher.Get())

                        {

                                // Adding all user names in our combobox

                                comboBox1.Items.Add(mObject["Name"]);

                        }

             }

             catch (Exception ex)

             {

                        MessageBox.Show(ex.ToString());

             }

    }

       private void Permissionbtn_Click_1(object sender, EventArgs e)
       {
           // retrieving the directory information

           DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);



           // Get a DirectorySecurity object that represents the 

           // current security settings.

           DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();

           string User = System.Environment.UserDomainName + "\\" +

                                                      comboBox1.SelectedItem.ToString();



           // Add the FileSystemAccessRule to the security settings. 

           // FileSystemRights is a big list we are current using Read property but you 

           // can alter any other or many sme of which are:

           // Create Directories: for sub directories Authority

           // Create Files: for files creation access in a particular folder
           // Delete: for deletion athority on folder

           // Delete Subdirectories and files: for authority of deletion over 

           //subdirectories and files

           // Execute file: For execution accessibility in folder

           // Modify: For folder modification

           // Read: For directory opening

           // Write: to add things in directory

           // Full Control: For administration rights etc etc



           // Also AccessControlType which are of two kinds either “Allow” or “Deny” 

           //myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User,

           //                                FileSystemRights.Read, AccessControlType.Allow));
           //myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User,

           //                                           FileSystemRights.Write, AccessControlType.Allow));

           myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User,

                                                      FileSystemRights.FullControl, AccessControlType.Allow));

           // Set the new access settings. 

           myDirectoryInfo.SetAccessControl(myDirectorySecurity);



           // Showing a Succesfully Done Message

           MessageBox.Show("Permissions Altered Successfully");

       }
}
}

Open in new window

LVL 1
Netlink2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Are you running this program as an Administrator from an account that has Admin privileges?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Netlink2Author Commented:
good point, yes I am
0
Netlink2Author Commented:
The program actually works. The full control is under special permissions. I wasn't looking there. But your answer prompted me to look at that, so I'll give you the points.
0
Dave BaldwinFixer of ProblemsCommented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.