[SQL]SQL Server 已封鎖元件 'xp_cmdshell' 的 程序 'sys.xp_cmdshell' 之存取,該如何處理?

  • 47878
  • 0
  • 2011-01-25

SQL Server 已封鎖元件 'xp_cmdshell' 的 程序 'sys.xp_cmdshell' 之存取,因為此元件已經由此伺服器的安全性組態關閉,該如何處理?

 

一、問題描述

使用 xp_cmdshell  出現如下錯誤訊息,該如何處理?

訊息 15281,層級 16,狀態 1,程序 xp_cmdshell,行 1
SQL Server 已封鎖元件 'xp_cmdshell' 的 程序 'sys.xp_cmdshell' 之存取,因為此元件已經由此伺服器的安全性組態關閉。系統管理員可以使用 sp_configure 來啟用 'xp_cmdshell' 的使用。如需有關啟用 'xp_cmdshell' 的詳細資訊,請參閱《SQL Server 線上叢書》中的<介面區組態>(Surface Area Configuration)。

 

二、從 Facet 開啟或關閉 xp_cmdshell

1. 開啟 SQL Server Management Studio,連接伺服器後,如下圖按滑鼠右鍵,選擇 [Facet]。

 

2. 此時出現 [檢視 facet] 視窗,找出 [XPCmdShellEnabled] 選擇 [True]。

 

三、透過 SQL 語法開啟或關閉 xp_cmdshell

-- 開啟 xp_cmdshell
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;

-- 關閉 xp_cmdshell
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 0;
RECONFIGURE;