SQL server and sql agent service account.

  • Hi All,

    Can anyone help me to get a script or command executing which i can know the SQL server and sql agent service account name and whether it is autostart or not.

    I know we can view this in SQL server properties, but i want a script or any command to know this.

    Thanks.

  • Hello,

    I believe you can get this information programmatically via WMI. Please see this article: http://www.databasejournal.com/features/mssql/article.php/3709441

    It talks about changing the ServiceAccount property, but I guess you could just display it instead.

    Regards,

    John Marsh

    www.sql.lu
    SQL Server Luxembourg User Group

  • To find the service account:-

    SET NOCOUNT ON

    USE MASTER;

    DECLARE @serviceaccount varchar(100),

    @agentaccount varchar(100)

    --Retrieve the Service account from registry

    EXECUTE master.dbo.xp_instance_regread

    N'HKEY_LOCAL_MACHINE',

    N'SYSTEM\CurrentControlSet\Services\MSSQLSERVER',

    N'ObjectName',

    @ServiceAccount OUTPUT,

    N'no_output'

    --Display the Service Account

    SELECT @Serviceaccount

    --Retrieve the Agent account from registry

    EXECUTE master.dbo.xp_instance_regread

    N'HKEY_LOCAL_MACHINE',

    N'SYSTEM\CurrentControlSet\Services\SQLSERVERAGENT',

    N'ObjectName',

    @agentaccount OUTPUT,

    N'no_output';

    SELECT @agentaccount

    Facts are stubborn things, but statistics are more pliable - Mark Twain
    Carolyn
    SQLServerSpecialists[/url]

  • Hello Carolyn,

    I guess your script would only work for the default instance - wouldn’t it?

    Regards,

    John Marsh

    www.sql.lu
    SQL Server Luxembourg User Group

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

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