Unas pequeñas líneas pueden ahorrarnos algún que otro lío (experiencia personal esta semana :-)
Podéis crear una variable o una pequeña tabla temporal:
-- xp_cmdshell configuration -- CREATE TABLE #config (val int) INSERT INTO #config SELECT convert(int, vlaue_in_use) FROM master.sys.configurations WHERE name= 'xp_cmdshell' IF (SELECT val FROM #config)= 0 -- enable xp_cmdshell and lock it again after completed the script BEGIN EXEC sp_configure 'show advanced options', 1 RECONFIGURE EXEC sp_configure 'xp_cmdshell',1 RECONFIGURE END --AQUI EL CÓDIGO -- set xp_cmdshell as its previous state if it was changed IF (SELECT val FROM #config) = 0 BEGIN EXEC sp_configure 'show advanced options', 1 RECONFIGURE EXEC sp_configure 'xp_cmdshell',0 RECONFIGURE END DROP TABLE #config
Lo mismo para OLE Automatation