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 N'HKEY_LOCAL_MACHINE', N'SYSTEM\CurrentControlSet\Services\MSSQLSERVER', N'ObjectName', @ServiceAccountName OUTPUT, N'no_output' SELECT @ServiceaccountName
Depending on whether the instance is Named Instance or not, the value SYSTEM\CurrentControlSet\Services\MSSQLSERVER needs to be changed appropriately.