CREATE PROC AutoStart_SQLAgent AS BEGIN /*********************************************************************************************************** Copyright © 2001 Narayana Vyas Kondreddi. All rights reserved. Purpose: To autostart SQL Server agent when SQL Server starts on a Windows 95 or Windows 98 computer Written by: Narayana Vyas Kondreddi http://vyaskn.tripod.com Tested on: SQL Server 7.0, SQL Server 2000 Date modified: October-15-2001 07:33 PM IST Email: vyaskn@hotmail.com Usage: Just run this complete script in the master database. This script creates a stored procedure that autostarts SQL Server Agent, when SQL Server starts. This procedure will be marked as a startup procedure, so that it runs everytime SQL Server service starts. For this approach to work successfully, the 'scan for startup procs' option should be 1. This option can be changed by using sp_configure system stored procedure. Notice the @ServiceName variable in the code, which holds the name of the SQL Server Agent service. In SQL Server 7.0 the SQL Server Agent service name will always be SQLServerAgent. In case of SQL Server 2000, the SQL Server Agent's service name for a default instance would be SQLAgent. If you have a named instance of SQL Server 2000, the SQL Server Agent service name will be SQLAgent$InstanceName, where InstanceName is the name of the SQL Server named instance. In the above two cases, you will have to set the appropriate value for @ServiceName variable. Upon successfully starting the SQL Server Agent, this procedure will log a message in the SQL Server error log saying "Successfully started SQL Server Agent". ***********************************************************************************************************/ DECLARE @Err int, @Msg varchar(100), @ServiceName sysname SET @ServiceName = 'SQLServerAgent' EXEC master.dbo.xp_servicecontrol 'START', @ServiceName SET @Err = @@ERROR IF @Err = 0 BEGIN RAISERROR ('Successfully started SQL Server Agent', 1, 1) WITH LOG END ELSE BEGIN SET @Msg = 'Error occured while starting SQL Server Agent. Error code: ' + STR(@Err) RAISERROR (@Msg, 18, 1) WITH LOG END END GO EXEC sp_procoption 'AutoStart_SQLAgent', 'startup', 'true' GO