xp_cmdshell 服务器配置选项xp_cmdshell Server Configuration Option

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

xp_cmdshell 选项是 SQL ServerSQL Server 服务器配置选项,该选项使系统管理员能够控制是否可以在系统上执行 xp_cmdshell 扩展存储过程。The xp_cmdshell option is a SQL ServerSQL Server server configuration option that enables system administrators to control whether the xp_cmdshell extended stored procedure can be executed on a system. 新安装中默认禁用 xp_cmdshell 选项 。By default, the xp_cmdshell option is disabled on new installations. 启用此选项前,请务必考虑使用此选项相关的潜在安全隐患。Before enabling this option, it is important to consider the potential security implications associated with the use of this option. 新开发的代码不应使用此选项,因为它通常应处于禁用状态。Newly-developed code should not use this option as it should generally be left disabled. 某些旧版应用程序需要启用此选项,如果不能将它们修改为避免使用此选项,可以使用基于策略的管理或运行 sp_configure 系统存储过程来启用此选项(如下面的代码示例所示) :Some legacy applications require it to be enabled, and if they cannot be modified to avoid the use of this option, it can be enabled by using the Policy-Based Management or by running the sp_configure system stored procedure as shown in the following code example:

-- To allow advanced options to be changed.  
EXEC sp_configure 'show advanced options', 1;  
GO  
-- To update the currently configured value for advanced options.  
RECONFIGURE;  
GO  
-- To enable the feature.  
EXEC sp_configure 'xp_cmdshell', 1;  
GO  
-- To update the currently configured value for this feature.  
RECONFIGURE;  
GO  

另请参阅See Also

服务器配置选项 (SQL Server) Server Configuration Options (SQL Server)
使用基于策略的管理来管理服务器Administer Servers by Using Policy-Based Management