June 14, 2005 at 6:54 am
Is there any SQL Server command to find out the owner of the SQL Server process and the SQL Server Agent process? Thanks for your help.
June 14, 2005 at 1:46 pm
If you mean, the login account for each of the SQL Services, this information is in the registry. Try this script:
set nocount on
set xact_abort on
DECLARE @RegistryPath varchar(200)
, @NamedInstanceInd char(1)
, @InstanceName varchar(128)
, @SQLServerSvcAccount varchar(128)
, @SQLAgentSvcAccount varchar(128)
, @DTCSvcAccount varchar(128)
, @SQLSearchSvcAccount varchar(128)
, @SQLServerStartUp varchar(128)
, @SQLAgentStartup varchar(128)
, @DTCStartup varchar(128)
, @SQLSearchStartup varchar(128)
create TABLE #RegistryEntry (value VARCHAR(50), data VARCHAR(50))
IF @@ServerName is null
OR (charindex('\',@@SERVERNAME)=0)
set @NamedInstanceInd = 'N'
else
begin
set @NamedInstanceInd = 'Y'
SET @InstanceName = RIGHT( @@SERVERNAME , LEN(@@SERVERNAME) - CHARINDEX('\',@@SERVERNAME))
END
-- SQL Server
SET @RegistryPath = 'SYSTEM\CurrentControlSet\Services\'
IF @NamedInstanceInd = 'N'
SET @RegistryPath = @RegistryPath + 'MSSQLSERVER'
else
set @RegistryPath = @RegistryPath + 'MSSQL$' + @InstanceName
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'ObjectName'
select @SQLServerSvcAccount = Data from #RegistryEntry
delete from #RegistryEntry
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'Start'
select @SQLServerStartUp = Data from #RegistryEntry
delete from #RegistryEntry
-- SQL AGENT
SET @RegistryPath = 'SYSTEM\CurrentControlSet\Services\'
IF @NamedInstanceInd = 'N'
SET @RegistryPath = @RegistryPath + 'SQLSERVERAGENT'
else
set @RegistryPath = @RegistryPath + 'SQLAgent$' + @InstanceName
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'ObjectName'
select @SQLAgentSvcAccount = Data from #RegistryEntry
delete from #RegistryEntry
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'Start'
select @SQLAgentStartup = Data from #RegistryEntry
delete from #RegistryEntry
-- Distributed Transaction Coordinator
SET @RegistryPath = 'SYSTEM\CurrentControlSet\Services\MSDTC'
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'ObjectName'
select @DTCSvcAccount = Data from #RegistryEntry
delete from #RegistryEntry
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'Start'
select @DTCStartup = Data from #RegistryEntry
delete from #RegistryEntry
-- Search (SQL Server )
SET @RegistryPath = 'SYSTEM\CurrentControlSet\Services\MSSearch'
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'ObjectName'
select @SQLSearchSvcAccount = Data from #RegistryEntry
delete from #RegistryEntry
INSERT #RegistryEntry
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE' , @RegistryPath,'Start'
select @SQLSearchStartup = Data from #RegistryEntry
delete from #RegistryEntry
select @SQLServerSvcAccount as SQLServerSvcAccount
, @SQLAgentSvcAccount as SQLAgentSvcAccount
, @DTCSvcAccount as DTCSvcAccount
, @SQLSearchSvcAccount as SQLSearchSvcAccount
, @SQLServerStartUp as SQLServerStartUp
, @SQLAgentStartup as SQLAgentStartup
, @DTCStartup as DTCStartup
, @SQLSearchStartup as SQLSearchStartup
SQL = Scarcely Qualifies as a Language
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply