Allows to add privileges to Local Security Policy. You can use this class to add the LogOn as service privilege to an account.
Inheritance: IDisposable
Beispiel #1
0
        /// <summary>
        /// Set the Log-On As Service privilege to the given user.
        /// </summary>
        /// <param name="userName">The account name (domain\name).</param>
        /// <returns>True for success; otherwise, false.</returns>
        public static bool SetLogonAsServicePrivilege(string userName)
        {
            try {
                using (LocalSecurityPolicy policy = new LocalSecurityPolicy()) {
                    policy.AddLogonAsServicePrivilege(userName);
                    return(true);
                }
            } catch { }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Set the Log-On As Service privilege to the given user.
        /// </summary>
        /// <param name="userName">The account name (domain\name).</param>
        /// <returns>True for success; otherwise, false.</returns>
        public static bool SetLogonAsServicePrivilege(string userName)
        {
            try
            {
                using (LocalSecurityPolicy policy = new LocalSecurityPolicy())
                {
                    policy.AddLogonAsServicePrivilege(userName); 
                    return true; 
                }
            }
            catch { }

            return false;
        }