Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

SQL Server Service Check Utility Expand / Collapse
Author
Message
Posted Tuesday, November 16, 2010 6:37 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 18, 2014 8:25 AM
Points: 312, Visits: 1,108
John,

Good idea! Do you think we can all see this code of your? Originally, I did not include service accounts before we have a separate network for our production and development server so I did not think about adding that feature.

Glad to see everyone's ideas on how to enhance this code.

Thanks,

Rudy



Post #1021449
Posted Friday, November 19, 2010 8:15 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, April 17, 2014 1:41 AM
Points: 170, Visits: 1,400
Rudy,

The code below returns the names of SQLService and SQLAgent accounts.
Works on 2000, 2005 and 2008 as far as I can tell:


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 as 'SQLService Account'
IF CAST(SERVERPROPERTY('ServerName') AS varchar) LIKE '%\%' SET @NamedInstance = 1 ELSE SET @NamedInstance = 0


IF @NamedInstance = 0
BEGIN
SET @ServiceName = 'SQLSERVERAGENT'
END
ELSE
BEGIN
SET @ServiceName = 'SQLAgent$' + RIGHT(CAST(SERVERPROPERTY('ServerName') AS varchar),LEN(CAST(SERVERPROPERTY('ServerName') AS varchar)) - CHARINDEX('\',CAST(SERVERPROPERTY('ServerName') AS varchar),1))
END

SET @KEY_VALUE = 'SYSTEM\CurrentControlSet\Services\' + @ServiceName

EXECUTE master..xp_regread 'HKEY_LOCAL_MACHINE', @KEY_VALUE, 'ObjectName', @ServiceAccountName OUTPUT
SELECT @ServiceAccountName as 'SQLAgent Account'


Cheers,

JohnA

MCM: SQL2008
Post #1023550
Posted Friday, November 19, 2010 9:59 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, August 25, 2014 1:31 PM
Points: 93, Visits: 741
Hi,
I actually worked on this issue for almost half a day and I couldn't resolve a snack with John's code a few days ago, and I just gave up.

He uses the following
DECLARE @KEY_VALUE varchar(100)
DECLARE @ServiceAccountName varchar(100)

EXECUTE master..xp_regread 'HKEY_LOCAL_MACHINE', @KEY_VALUE, 'ObjectName', @ServiceAccountName OUTPUT
SELECT @ServiceAccountName as 'SQLAgent Account'

however, I've run that code on several servers and in some of them the result is 'NULL'.
(it doesn't matter the service, it happens with several services).

The only thing I could figure out is that when I run the following code:

declare @regkey varchar (100)
SET @REGKEY = 'System\CurrentControlSet\Services\SQLAgent$instance_name'

EXEC master..xp_regenumvalues @rootkey='HKEY_LOCAL_MACHINE',@key=@regkey

for the Object value I get the following:
Value                 data	 value	 data
ObjectName .\sqlservice NULL NULL

It seems that for some cases the registry key has two sets of values, weird.

Anyone has ideas of why this might be?

Thank you

Miguel
Post #1023665
Posted Sunday, December 12, 2010 2:19 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 9:59 AM
Points: 27, Visits: 551
Excellent script, Rudy. Thanks a mint for sharing it.


Post #1033523
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse