The below Script can be used to find the service accounts for SQL Server. (SQL 2012,SQL 2016 onwards)
SELECT DSS.servicename,
DSS.startup_type_desc,
DSS.status_desc,
DSS.last_startup_time,
DSS.service_account,
DSS.is_clustered,
DSS.cluster_nodename,
DSS.filename,
DSS.startup_type,
DSS.status,
DSS.process_id
FROM sys.dm_server_services AS DSS;
In SQL Server 2005 and 2008, the below query can be used to retrieve the service account information.
DECLARE @sn NVARCHAR(128);
EXEC master.dbo.xp_regread
'HKEY_LOCAL_MACHINE',
'SYSTEM\CurrentControlSet\services\SQLSERVERAGENT',
'ObjectName',
@sn OUTPUT;
SELECT @sn;