June 19, 2008 at 12:48 pm
Hi all,
Is there some way to query what they SQL service account is from either query analyzer/management studio or the command line?
Im trying to come up with an automated way of gathering all of the service accounts on my servers so that I dont have to log in to each one (over 100) to inventory them.
I was thinking something like @@SERVERNAME only for the service account.
Any ideas?
June 19, 2008 at 1:30 pm
Here's some code that I'm using.
DECLARE @NamedInstance bit
IF CAST(SERVERPROPERTY('ServerName') AS varchar) LIKE '%\%' SET @NamedInstance = 1 ELSE SET @NamedInstance = 0
DECLARE @ServiceName varchar(50)
IF @NamedInstance = 0
BEGIN
SET @ServiceName = 'MSSQLSERVER'
END
ELSE
BEGIN
SET @ServiceName = 'MSSQL$' + RIGHT(CAST(SERVERPROPERTY('ServerName') AS varchar),LEN(CAST(SERVERPROPERTY('ServerName') AS varchar)) - CHARINDEX('\',CAST(SERVERPROPERTY('ServerName') AS varchar),1))
END
DECLARE @KEY_VALUE varchar(100)
DECLARE @ServiceAccountName varchar(100)
SET @KEY_VALUE = 'SYSTEM\CurrentControlSet\Services\' + @ServiceName
EXECUTE master..xp_regread 'HKEY_LOCAL_MACHINE', @KEY_VALUE, 'ObjectName', @ServiceAccountName OUTPUT
SELECT @ServiceAccountName
Ola Hallengren
June 19, 2008 at 1:43 pm
Works perfect. Thanks Ola!
August 25, 2010 at 3:29 am
Excellent advice.
August 25, 2010 at 5:32 am
Useful utility, thanks:-)
Cheers,
JohnA
MCM: SQL2008
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply