SQL Server extended stored procedure – xp_servicecontrol

Oopps! Upgrade your browser pretty please.Oopps! Upgrade your browser pretty please.

In SQL server there is an undocumented extended stored procedure called xp_servicecontrol. You can use this to start/stop and view the state of the SQL server services. The syntax is very simple, exec xp_servicecontrol querystate|start|stop, servicename. If you are using named instances, you need to use the servicename$instancename, see the sample below: 

--get the state of the SQL Services (default instances)
EXEC xp_servicecontrol N'querystate',N'MSSQLServer'
EXEC xp_servicecontrol N'querystate',N'SQLServerAGENT'
EXEC xp_servicecontrol N'querystate',N'msdtc'
EXEC xp_servicecontrol N'querystate',N'SQLbrowser'

-- if you are running named instances, you have to add the instance name
EXEC xp_servicecontrol N'querystate',N'MSSQLServer$SQL2012'
EXEC xp_servicecontrol N'querystate',N'SQLAGENT$SQL2012'
EXEC xp_servicecontrol N'querystate',N'ReportServer$SQL2012'

--start/stop service using SSMS
EXEC xp_servicecontrol N'stop',N'SQLAGENT$SQL2012'
EXEC xp_servicecontrol N'start',N'SQLAGENT$SQL2012'

--you can actually check non-SQL Services
EXEC xp_servicecontrol 'querystate', 'MSMQ'

Keep in mind that  the xp_servicecontrol procedure is undocumented and unsupported.