The EXECUTE permission was denied on the object ‘xp_cmdshell’, database ‘mssqlsystemresource’, schema ‘sys’

A user will usually receive this error message when trying to execute xp_cmdshell and does not have sufficient permissions.

To grant permissions to execute xp_cmdshell using TSQL, run the query below.

USE [master];

GRANT EXECUTE
ON xp_cmdshell
TO [Domain\LoginName]

To test this works I usually run the query below.

EXECUTE xp_cmdshell 'DIR'

To test the granted execute permissions work for the intended user, I impersonate them to run the xp_cmdshell query under their security context. I have also written another post on how to impersonate a login and how to grant IMPERSONATE permissions on a login.


Leave a Reply

Your email address will not be published. Required fields are marked *