Xp_mongoshell
-- The xp_cmdshell option introduced in SQL Server 2005 is the Server configuration option, which enables the system administrator to control whether the xp_cmdshell extension stored procedure can be executed on the system. By default, the xp_cmdshell option is disabled on the newly installed software, but you can enable it by using the peripheral application configurator tool or running the sp_configure system stored procedure, the following code example is as follows:
| The code is as follows: |
Copy code |
-- To allow advanced options to be changed. -- Allow advanced options to be changed EXEC sp_configure 'show advanced options', 1 GO -- To update the currently configured value for advanced options. -- Update the current configuration value as an advanced option RECONFIGURE GO -- To enable the feature. -- Enable this feature EXEC sp_configure 'XP _ your shell', 1 GO -- To update the currently configured value for this feature. -- Update the current configuration value to this feature. RECONFIGURE GO |
Another method is sp_xp_cmdshell to enable and disable xp_cmdshell instances.
| The code is as follows: |
Copy code |
[SQL] USE master GO IF OBJECT_ID ('sp _ xp_cmdshell ', 'P') IS NOT NULL Drop proc sp_xp_cmdshell GO Create procedure sp_xp_mongoshell @ OnOff CHAR (3) = 'on' AS /* Author: Chen Enhui-Hong En Example: Exec sp_xp_cmdshell @ OnOff = 'on' -- enable the xp_cmdshell function Exec sp_xp_cmdshell @ OnOff = 'off' -- disable xp_cmdshell. */ If upper (@ OnOff) not in ('on', 'off ') BEGIN SELECT 'parameter @ OnOff can only be ON, Off' AS return_result RETURN END If upper (@ OnOff) = 'on' BEGIN -- Allow advanced configuration options EXEC master. sys. sp_configure 'show advanced options', 1 -- Reconfigure RECONFIGURE -- Enable xp_cmdshell EXEC master. sys. sp_configure 'XP _ your shell', 1 -- Reconfigure RECONFIGURE END ELSE BEGIN -- Disable xp_cmdshell EXEC master. sys. sp_configure 'XP _ your shell', 0 -- Reconfigure RECONFIGURE -- Disable advanced configuration options EXEC master. sys. sp_configure 'show advanced options', 0 -- Reconfigure RECONFIGURE END GO EXEC sp_MS_marksystemobject 'sp _ xp_cmdshell' GO |