SQL Server Services Account are stored in registry keys. You can read those key using built-in stored procedure “xp_instance_regread”. These account information are stored under following keys HKEY_LOCAL_MACHINE --> SYSTEM --> CurrentControlSet --> services –> InstanceName
Instance Name: It is MSSQLServer for Default Instance. and if you have named instance then it is MSSQL$instancename. For example if you instance name is “Server\Prod” so your instance will be MSSQL$Prod.
Now you can use following query to find service account Name of SQL Server Service.
DECLARE @ServiceaccountName varchar(250)
EXECUTE master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE', N'SYSTEM\CurrentControlSet\Services\MSSQLSERVER',
N'ObjectName',@ServiceAccountName OUTPUT, N'no_output'
SELECT @ServiceAccountName
Similarly you can also get Account Name For SQL Server Agent. Following query gets you SQL Server Agent Account for default instance. You can specify SQLAgent$Instancename if you have named instance installed.
DECLARE @ServiceaccountName varchar(250)
EXECUTE master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE', N'SYSTEM\CurrentControlSet\Services\SQLServeragent',
N'ObjectName',@ServiceAccountName OUTPUT, N'no_output'
SELECT @ServiceAccountName
thanks, it was helpful
ReplyDeleteNice!
ReplyDeleteExcellent. Thanks
ReplyDelete