/// <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);
}