We can use below query to get information about Sql Service Account information.
1: SELECT value_data
2: FROM sys.dm_server_registry
3: WHERE value_name = 'ObjectName'
4: AND registry_key = 'HKLM\SYSTEM\CurrentControlSet\Services\MSSQLSERVER'
For Sql Server Agent, we can use below query.
1: SELECT value_data
2: FROM sys.dm_server_registry
3: WHERE value_name = 'ObjectName'
4: AND registry_key = 'HKLM\SYSTEM\CurrentControlSet\Services\MSSQLSERVERAGENT'
There are other approaches to get this information.
1: SELECT DSS.servicename,
2: DSS.startup_type_desc,
3: DSS.status_desc,
4: DSS.last_startup_time,
5: DSS.service_account,
6: DSS.is_clustered,
7: DSS.cluster_nodename,
8: DSS.filename,
9: DSS.startup_type,
10: DSS.status,
11: DSS.process_id
12: FROM sys.dm_server_services AS DSS