xp_cmdshell 伺服器組態選項xp_cmdshell Server Configuration Option

適用於: 是SQL Server 否Azure SQL Database 否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