SQL Tips by Namwar Rizvi

August 6, 2007

Retrieve SQL Server Service account name from registry through TSQL

Filed under: Information,SQL Server 2005,tips,TSQL — namwar @ 7:56 PM

Here is a quick and easy way to get the account name under which current SQL Server service is running. This script will also teach you how you can use an undocumented extended stored procedure to read windows registry through TSQL. I got this code from Microsoft newsgroup and I have checked it on SQL Server 2005. All credit goes to the actual writer of the code.

–Declare a variable to hold the value
DECLARE @serviceaccount varchar(100)

—Retrieve the Service account from registry
EXECUTE master.dbo.xp_instance_regread
@ServiceAccount OUTPUT,

—Display the Service Account
SELECT @Serviceaccount



  1. hi,

    what if the sql server is a named instance?


    Comment by Michael — February 27, 2012 @ 12:50 AM | Reply

  2. @Michael .. that’s the point of xp_instance_regread .. it handles that for you.

    Comment by Oliver Holloway — February 29, 2012 @ 8:37 PM | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: