• Use this:=

    IF NOT EXISTS (SELECT value_in_use

    FROM sys.configurations

    WHERE name = 'xp_cmdshell'

    AND value_in_use = 1)

    BEGIN

    EXEC ('sp_configure ''show advanced options'', 1')

    RECONFIGURE;

    EXEC ('sp_configure ''xp_cmdshell'', 1')

    RECONFIGURE;

    EXEC ('sp_configure ''show advanced options'', 0')

    RECONFIGURE;

    END

    Thanks.