SQL Server – xp_cmdshell

Windows commands can be run from SQL Server, if xp_cmdshell is enabled on the SQL Server instance. We can check if this is enabled from the system view sys.configurations.

-- CHECK FOR "xp_cmdshell"
SELECT name, CONVERT(INT, ISNULL(value, value_in_use)) AS IsConfigured 
FROM sys.configurations 
WHERE name = 'xp_cmdshell';

-- CHECK FOR "show advanced options"
SELECT name, CONVERT(INT, ISNULL(value, value_in_use)) AS IsConfigured 
FROM sys.configurations 
WHERE name = 'show advanced options';