枚举SQL中的Agent代理 Agent use msdbgoif exists (select * from sysobjects where name = N'sp_sqlagent_enum_errorlogs' and type ='P') drop proc dbo.sp_sqlagent_enum_errorlogsgocreate proc dbo.sp_sqlagent_enum_errorlogsasset nocount ondeclare @
枚举SQL中的Agent代理 Agentuse msdb
go
if exists (select * from sysobjects where name = N'sp_sqlagent_enum_errorlogs' and type ='P')
drop proc dbo.sp_sqlagent_enum_errorlogs
go
create proc dbo.sp_sqlagent_enum_errorlogs
as
set nocount on
declare @rc int
declare @version int
declare @pos int
declare @errorlog_file nvarchar(255)
declare @filename nvarchar(255)
declare @filename_no_ext nvarchar(255)
declare @dirname nvarchar(255)
declare @buf nvarchar(255)
-- SQL Server 7.0
if (charindex(N'7.00', @@version, 0) > 0)
begin
exec @rc = master.dbo.xp_regread
N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'ErrorLogFile',
@errorlog_file OUTPUT,
N'no_output'
end
-- SQL Server 2000 needs to use instance aware Registry read
if (charindex(N'8.00', @@version, 0) > 0)
begin
exec @rc = master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent',
N'ErrorLogFile',
@errorlog_file OUTPUT,
N'no_output'
end
-- reverse the string to find the last slash '\'
select @buf = reverse(@errorlog_file)
-- determine posiktion of last slash, now first slash in reversed string
select @pos = len(@buf) - charindex(char(92), @buf, 0) + 1
-- extract the directory only part, part before the last slash
select @dirname = substring(@errorlog_file, 0, @pos)
-- extract the filename, part after the last slash
select @filename = substring(@errorlog_file, @pos + 1, len(@errorlog_file) - @pos)
-- extract the filename with extension, part after dot in @filename
select @filename_no_ext = substring(@filename, 0, charindex(N'.', @filename, 0))
-- since xp_dirtree does not allow any filters, create temp table to store results
create table #t
(
[subdirectory] nvarchar(255) not null,
[depth] int not null,
[file] int not null
)
-- add all file names to the temp table
insert into #t exec master.dbo.xp_dirtree @dirname, 1, 1
-- retrieve only files that match @filename_no_ext%
select [name] = subdirectory from #t where subdirectory like @filename_no_ext + '%' order by [name]
drop table #t
go
-- sample usage
-- exec msdb.dbo.sp_sqlagent_enum_errorlogs
-- go
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号