Discover the Service Account

  • I'm running an SSIS package to loop through servers and get various information that I can consolidate into one place.

    Does anyone know what query would grab the account name that SQL Server and the agent are running under on each box?

    I've done a bit of searching but I'm coming up blank.

  • Try something like this!

    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

    Regards,

    Prakash.


    Kindest Regards,

    R

  • Thanks, that got me started. Now I can just use the same on SQLServerAgent and I'm good to go.

  • Got this from this site I believe way back, this checks to see if it is a named instance and routes the registry accordingly

    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

    Andrew

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply