Exemple #1
0
        /// <summary>
        /// Expires the specified user or computer's password, forcing it to be required to be reset.
        /// </summary>
        /// <param name="name">The unique identifier of the user or computer.</param>
        /// <returns>True if the password was expired successfully, false otherwise.</returns>
        public static Boolean ExpirePassword(string name)
        {
            Boolean result = false;

            try
            {
                Principal p = Principal.FindByIdentity(GetPrincipalContext(), name);

                if ((p != null) && (p is UserPrincipal))
                {
                    UserPrincipal u = p as UserPrincipal;
                    u.ExpirePasswordNow();
                    u.Save();
                    result = true;
                }
                else if ((p != null) && (p is ComputerPrincipal))
                {
                    ComputerPrincipal c = p as ComputerPrincipal;
                    c.ExpirePasswordNow();
                    c.Save();
                    result = true;
                }
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Unlocks the specified principal, which can be either a user or computer.
        /// </summary>
        /// <param name="principal">A unique identifier of a user or computer.</param>
        /// <returns>True if success, false otherwise.</returns>
        public static Boolean Unlock(string principal)
        {
            Principal p = Principal.FindByIdentity(GetPrincipalContext(), principal);

            try
            {
                if (p is UserPrincipal)
                {
                    UserPrincipal u = p as UserPrincipal;
                    u.UnlockAccount();
                    u.Save();
                }
                else if (p is ComputerPrincipal)
                {
                    ComputerPrincipal c = p as ComputerPrincipal;
                    c.UnlockAccount();
                    c.Save();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a computer with the specified name and description in the specified location.
        /// </summary>
        /// <param name="name">The name of the new computer.</param>
        /// <param name="location">The distinguished name of the OU in which the computer should be created.</param>
        /// <param name="description">The description of the new computer.</param>
        /// <returns>A ComputerPrincipal object representing the new computer.</returns>
        public static ComputerPrincipal CreateComputer(string name, string location, string description)
        {
            ComputerPrincipal newComputer = new ComputerPrincipal(GetPrincipalContext(location), name, GetRandomPassword(), true);

            newComputer.Description = description;
            newComputer.DisplayName = name;
            newComputer.Name        = name;
            newComputer.Save();
            return(newComputer);
        }
Exemple #4
0
 /// <summary>
 /// Deletes the specified computer account.
 /// </summary>
 /// <param name="name">The unique identifier of the computer.</param>
 /// <returns>True if the computer was deleted, false if not or the computer doesn't exist.</returns>
 public static Boolean DeleteComputer(string name)
 {
     try
     {
         ComputerPrincipal c = ComputerPrincipal.FindByIdentity(GetPrincipalContext(), name);
         c.Delete();
         c.Save();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #5
0
        // Bilgisayar Kayit Methodu

        public string SaveComputer(string computerName, string yapisalBirim)
        {
            try
            {
                using (PrincipalContext principialContext = _computer.SetPrincipialContext(computerName, yapisalBirim))
                    using (ComputerPrincipal computerPrincipial = _computer.SetComputerPrincipial(principialContext))
                    {
                        computerPrincipial.SamAccountName = computerName;
                        computerPrincipial.Enabled        = true;
                        computerPrincipial.Save();
                        return("Başarı ile Kayıt Yapıldı");
                    }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemple #6
0
        public bool CreateComputerObject(string computerName)
        {
            //   string newcomputername = computerName + "@domain";
            ComputerPrincipal ComputerPrincipal = new ComputerPrincipal(context);

            ComputerPrincipal.Name = computerName;

            ComputerPrincipal.DisplayName    = computerName;
            ComputerPrincipal.SamAccountName = computerName + "$";
            ComputerPrincipal.Enabled        = true;
            ComputerPrincipal.Save();
            if (ComputerPrincipal != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }