Technical Article

Check if xp_cmdshell is turned on and flip the bit

,

In some shops \ cases this feature may be turned off as part of the security regulations. You may need to flip xp_cmdshell on to perform a piece work and then flip the bit back when the work is done. You can also tweak the code to flip the bit off again when done. Simple, non complex script but very effective in an automation task. The script uses sys.configurations to check the bit set for the xp_cmdshell feature, if the value = 0 we turn it on.  I hope you will find some use for the code.

Declare @value_in_use sql_variant
SELECT @value_in_use = value_in_use FROM sys.configurations where name = 'xp_cmdshell'
--Select @value_in_use
If @value_in_use = 0
Begin
Print 'Turning on xp_cmdshell'
exec sp_configure 'show advanced options','1'
RECONFIGURE WITH OVERRIDE;
exec sp_configure 'xp_cmdshell','1'
RECONFIGURE WITH OVERRIDE;
End
go

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating