Search code examples
c#access-rights

How to check a particular user has log on as service right programmatically


For an application I what to check whether a particular user has log on as a service right? How to do this programmatically? I checked in the Internet and could not find out some good resource

Thanks

Upul


Solution

  • Do you have a token for that account? If so you can call GetTokenInformation with TokenInformationClass == TokenPrivileges. That will return the list of privileges associated with the token and whether or not they have been activated.

    If the account isn't logged in and thus you can't get their token, it becomes much harder. You can't query for the privileges allowed for the account let alone the privileges that any of the account's groups bring into the token. You would need to logon the account to retrieve a token and then follow the previous advice.