.net - c# Granting "Log On As Service" permission to a windows user -


how grant user logonasservice right service?

i need manually, in services.msc app can go service, change password (setting same there before), click apply , message:

the account .\postgres has been granted log on service right.

how do code, because otherwise have give permission hand each time run application , not possibility

@steve

    static void main()     {         // irrelevant stuff          grantlogonasserviceright("postgres");          // irrelevant stuff     }      private static void grantlogonasserviceright(string username)     {         using (lsawrapper lsa = new lsawrapper())         {             lsa.addprivileges(username, "seservicelogonright");         }     } 

and lsa lib guy willy.

see granting user rights in c#.

you have invoke lsa apis via p/invoke, , url has reference wrapper class you. code end simple:

private static void grantlogonasserviceright(string username) {    using (lsawrapper lsa = new lsawrapper())    {       lsa.addprivileges(username, "seservicelogonright");    } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -