AddLogonAsServicePrivilege() public method

Add the privilege for the given account to logon as service.
public AddLogonAsServicePrivilege ( string account ) : void
account string The account name (domain\userName)
return void
コード例 #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);
        }
コード例 #2
0
ファイル: ServiceInstaller.cs プロジェクト: yuriik83/UA-.NET
        /// <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;
        }