Example #1
0
        static void Main()
        {
            Exchange myEx = new Exchange();
            //myEx.TestEnable();
            //myEx.enableMailbox("sccdc8pr01.ncu.local/NCU Users/SCC Users/Test Kameron");
            //myEx.disableMailbox("tkameron");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Example #2
0
        /// <summary>
        /// function that goes into active directory and expires the user account.
        /// </summary>
        private void ExpireAccount()
        {
            using (var context = new PrincipalContext(ContextType.Domain, Form1._Domain, Form1._AdminUser, Form1._Password))
            {
                string userOU = "";
                using (var foundUser = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, Form1.myForm.tbEmployeeID.Text))
                {
                    userOU = foundUser.DistinguishedName.ToString();
                }

                //string userOU = "CN=" + _displayName + ",OU=SCC Users,OU=NCU Users,DC=ncu,DC=local";
                AuthenticationTypes AuthTypes = AuthenticationTypes.Signing | AuthenticationTypes.Sealing | AuthenticationTypes.Secure;
                DirectoryEntry objADAM = new DirectoryEntry("LDAP://" + userOU, Form1._AdminUser, Form1._Password, AuthTypes);
                objADAM.RefreshCache();
                try
                {
                    objADAM.Properties["accountExpires"].Clear();
                    objADAM.Properties["accountExpires"].Add(DateTime.Today.AddDays(-1).ToFileTime().ToString());
                }
                catch (Exception ex)
                {
                    Form1.myForm._Notes.AppendLine();
                    Form1.myForm._Notes.Append("<br>Expire Account failed: " + ex.Message + "<br>");
                }
                try
                {
                    string oldManager = objADAM.Properties["manager"].Value.ToString();
                    objADAM.Properties["manager"].Clear();
                    Form1.myForm._Notes.AppendLine();
                    Form1.myForm._Notes.Append("<br>Manager cleared.<br>");
                    try
                    {
                        objADAM.Properties["altRecipient"].Value = oldManager;
                        Form1.myForm._Notes.AppendLine();
                        Form1.myForm._Notes.Append("<br>Mail forwarding to Manager<br>");
                    }
                    catch (Exception)
                    {
                        Form1.myForm._Notes.AppendLine();
                        Form1.myForm._Notes.Append("<br>Failed to set Mail Forwarding.<br>");
                    }
                    // give manager full access to users mailbox

                    Exchange myEx = new Exchange();
                    myEx.giveEmailControl(Form1.myForm.tbEmployeeID.Text,oldManager);
                }
                catch (Exception)
                {
                    Form1.myForm._Notes.AppendLine();
                    Form1.myForm._Notes.Append("<br>Manager failed to clear or not assigned one.<br>");
                }

                try
                {
                    string oldDescription = objADAM.Properties["description"].Value.ToString();
                    objADAM.Properties["description"].Value = DateTime.Now.ToShortDateString() + " " + oldDescription;
                }
                catch (Exception)
                {
                    Form1.myForm._Notes.AppendLine();
                    Form1.myForm._Notes.Append("<br>No description: Ignored<br>");
                }
                try
                {
                    objADAM.Properties["msExchHideFromAddressLists"].Value = "TRUE";
                    Form1.myForm._Notes.AppendLine();
                    Form1.myForm._Notes.Append("<br>Account removed from Outlook contact list.<br>");
                }
                catch (Exception)
                {
                    Form1.myForm._Notes.AppendLine();
                    Form1.myForm._Notes.Append("<br>No email setting: Ignored<br>");
                }

                objADAM.CommitChanges();
                objADAM.Dispose();
            }
        }