How to Turn on xp_cmdshell for SQL 2005

The xp_cmdshell function can be very helpful for running commands on an SQL server. However, turning on the function comes with risks. I’ll discuss those risks later… If you try to run xp_cmdshell on a server where it is not turned on, you may receive this error message:

Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
SQL Server blocked access to procedure ‘sys.xp_cmdshell’ of component ‘xp_cmdshell’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘xp_cmdshell’ by using sp_configure. For more information about enabling ‘xp_cmdshell’, see “Surface Area Configuration” in SQL Server Books Online.

To turn xp_cmdshell on, log in to the SQL server as sa, and run this command:

USE master
GO
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_configure 'show advanced options', 0
GO

Leave a Reply