Query to find out Service Account details

I came across a question recently “How to find out under which account the SQL Services are running?”. Not through the GUI but through script.

This information is stored in the Windows Registry.

If the SQL Server is a Named instance then this key will be named as MSSQL$InstanceName. Similarly the SQL Server Agent key will be named SQLSERVERAGENT and SQLAGENT$InstanceName respectively for Default and Named Instances.

This information can be obtained from the registry using xp_instance_regread extended stored procedure in T-SQL. Here is a sample.

DECLARE @ServiceaccountName varchar(250)
EXECUTE master.dbo.xp_instance_regread
@ServiceAccountName OUTPUT,

SELECT @ServiceaccountName

Depending on whether the instance is Named Instance or not, the value SYSTEM\CurrentControlSet\Services\MSSQLSERVER needs to be changed appropriately.

2 thoughts on “Query to find out Service Account details

  1. Maha

    “This is not for Post, Just a private converstion”. This was going through my mind every time i read a article from you on windows registry. How did you master it, i really admired that. Shall we have a session on introducing Windows registry for our team. Please let me know about it in the team huddle.

  2. Pingback: Mayday! Mayday! Service wont start! « SQL DBA In Training

Comments are closed.