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)
,@NamedInstanceIndchar(1)
,@InstanceNamevarchar(128)
,@SQLServerSvcAccountvarchar(128)
,@SQLAgentSvcAccountvarchar(128)
,@DTCSvcAccountvarchar(128)
,@SQLSearchSvcAccountvarchar(128)
,@SQLServerStartUpvarchar(128)
,@SQLAgentStartupvarchar(128)
,@DTCStartupvarchar(128)
,@SQLSearchStartupvarchar(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@SQLServerSvcAccountas SQLServerSvcAccount
,@SQLAgentSvcAccountas SQLAgentSvcAccount
,@DTCSvcAccountas DTCSvcAccount
,@SQLSearchSvcAccountas SQLSearchSvcAccount
,@SQLServerStartUpas SQLServerStartUp
,@SQLAgentStartupas SQLAgentStartup
,@DTCStartupas DTCStartup
,@SQLSearchStartupas 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