You are here:Home » tsql » know serviceAccount sql_registry

know serviceAccount sql_registry

First:

DECLARE @account varchar(100)
EXECUTE master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'SYSTEM\CurrentControlSet\Services\MSSQLSERVER',
N'ObjectName',
@account OUTPUT,
N'no_output'

SELECT @account as SQLServer_ServiceAccount



Second:


declare @reg_srv varchar(256),
@reg_agent varchar(256)

if serverproperty('instancename') is null
begin --default instance
set @reg_srv='SYSTEM\CurrentControlSet\SERVICES\MSSQLSERVER'
set @reg_agent='SYSTEM\CurrentControlSet\SERVICES\SQLSERVERAGENT'
end
else
begin --named instance
set @reg_srv='SYSTEM\CurrentControlSet\SERVICES\MSSQL$'+cast (serverproperty('instancename') as sysname)
set @reg_agent='SYSTEM\CurrentControlSet\SERVICES\SQLAgent$'+cast (serverproperty('instancename') as sysname)
end
exec master..xp_regread
'HKEY_LOCAL_MACHINE', @reg_srv, 'ObjectName'
exec master..xp_regread
'HKEY_LOCAL_MACHINE', @reg_agent, 'ObjectName'
go