–xp_cmdshell 'dir e:\mssql\reports'
–Msg 229, Level 14, State 5, Procedure xp_cmdshell, Line 1
–The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.
EXEC sp__cmdshell 'dir e:\mssql\reports'
Works!
Here's the procedure:
CREATE PROCEDURE [dbo].[sp__cmdshell] (
@vcCmd VARCHAR(8000),
@bNoOutput bit = 0
)
AS
SET nocount ON
DECLARE @RC INT
IF @bNoOutput = 0
EXEC @RC = master.dbo.xp_cmdshell @vcCmd
ELSE
EXEC @RC = master.dbo.xp_cmdshell @vcCmd, no_output
IF @RC <> 0 OR @@ERROR <> 0
PRINT 'ERROR: ' + @vcCmd
RETURN @RC
GO
You probably also need to give permissions to a login or a role to run the new procedure.
GRANT EXECUTE ON [dbo].[sp__cmdshell] TO [db_executor]