(Starred out sensitive details for obvious reasons)
The problem line of code is :
int val = (int)user.Properties["userAccountControl"].Value;
I tried instantiating int val before the try catch, but that doesn't seem to do it. I am guessing that I am incorrectly converting the userAccountControl value to an int that's why it is outputting it as a null value. I have tried moving the (int) function around the line.
I also tried adding parenthesis around the whole thing :
((int)user.Properties["userAccountControl"].Value);
The disable function :
   public void Disable(string userDn)
   {
        try
        {
            DirectoryEntry user = new DirectoryEntry(userDn);
            user.Path = "LDAP://******";
            user.Username = @"********";
            user.Password = "*******";
            int val = (int)user.Properties["userAccountControl"].Value;
            user.Properties["userAccountControl"].Value = val | 0x2;
      
            user.CommitChanges();
            user.Close();
        }
        catch (System.DirectoryServices.DirectoryServicesCOMException E)
        {
            MessageBox.Show(E.Message.ToString());
        }
    }
This is the userDn string and how I run the Disable function:
Disable("CN=Bob Ross,OU=***,DC=***,DC=***");    
Any help would be much appreciated
Thank you
 
     
    