4

我尝试xp_cmdshell在 SQL Server 中启用。所以我跑了:

EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE 

返回的消息说:

配置选项“显示高级选项”从 1 更改为 1。运行 RECONFIGURE 语句进行安装。

配置选项“xp_cmdshell”从 0 更改为 1。运行 RECONFIGURE 语句进行安装。

构面属性显示“XPCmdShellEnabled”

但是,当我执行

EXEC master..xp_cmdshell 'dir c:'

我收到错误消息

消息 15281,级别 16,状态 1,过程 xp_cmdshell,第 1 行
SQL Server 阻止了对组件“xp_cmdshell”的过程“sys.xp_cmdshell”的访问,因为该组件作为该服务器的安全配置的一部分被关闭。系统管理员可以使用 sp_configure 启用“xp_cmdshell”的使用。有关启用“xp_cmdshell”的详细信息,请参阅 SQL Server 联机丛书中的“表面区域配置”。

我所做的是来自 Microsoft 文档。为什么它不起作用?

4

2 回答 2

11

让我们试试这个:禁用它,然后重新启用它。

--Disable
Use Master

GO
EXEC master.dbo.sp_configure 'xp_cmdshell', 0
RECONFIGURE WITH OVERRIDE

GO

EXEC master.dbo.sp_configure 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
GO

-- Enable
Use Master
GO
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO

EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
GO
于 2015-07-01T21:49:10.650 回答
3

您可以从 SQL Server Management Studio 执行此操作,如下所示:

  1. 右键单击服务器,然后选择Facets
  2. 选择刻面Surface Area Configuration
  3. 将属性设置XPCmdShellEnabledTrue

在此处输入图像描述

于 2016-11-15T07:00:13.093 回答