Search code examples
c#sql-serverserviceaccount

How to get the account the SQL Server service runs as with C#?


Ideally, I would like to pass a SQL Server instance name (for instance, .\SQLEXPRESS) and get the name (or a SID) of the account that particular instance is running as. Something like this:

var serviceAccount = SomeClass.GetServiceAccount(".\SQLEXPRESS");

Maybe this info is stored somewhere in system registry or other well-known location? Any ideas?


Solution

  • Try this: "Query to find out Service Account details"