自动开始SQL的Agent代理

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

-- sp_sqlagent_autostart
-- created by gertd@sqldev.net
-- NOTE: works on NT/Win2K/WinXP only, not in Win9x
--
use master
go 

if exists (select * from sysobjects where name = 'sp_sqlagent_autostart' and type = 'P')
    drop proc dbo.sp_sqlagent_autostart
go

create proc dbo.sp_sqlagent_autostart
as
set nocount on

declare @service nvarchar(128)

if (charindex(N'7.00', @@version, 0) > 0)
begin
    select @service = N'SQLServerAgent'
end

if (charindex(N'8.00', @@version, 0) > 0)
begin
    if (serverproperty('instancename') is null)
        select @service = N'SQLServerAgent'
    else
        select @service = N'SQLAgent$' + convert(nvarchar(128), serverproperty('InstanceName'))
end

exec master.dbo.xp_servicecontrol 'START', @service
go

exec master.dbo.sp_procoption 'sp_sqlagent_autostart', 'startup', 'true'
go