SQL SERVER-开启xp_cmdshell

SQL SERVER-开启xp_cmdshell

在sql server中执行cmd命令,报以下异常。

EXEC master.sys.xp_cmdshell 'dir c:/'

Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1 [Batch Start Line 44]
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', search for 'xp_cmdshell' in SQL Server Books Online.

 

 服务器开启

--Server config

EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'xp_cmdshell',1;
GO
RECONFIGURE;
GO

 

如果是sysadmin账号则可以执行了,若不是则要做以下配置。

 

添加代理账号,注意一定用windows账号登陆SSMS,在执行

EXEC sp_xp_cmdshell_proxy_account 'abc\cc','xx'

 否则会报以下异常,其余异常如权限不够,则用管理员启动SSMS或则账号密码错误,还有一定要加域名如果本地则EXEC sp_xp_cmdshell_proxy_account 'sdsdbt16b\Jinwei','vv12345',一定写成本地主机名才行

An error occurred during the execution of sp_xp_cmdshell_proxy_account.
Possible reasons: the provided account was invalid or the '##xp_cmdshell_proxy_account##' credential could not be created.
Error code: 0(null), Error Status: 0.

 

在master下建立相应用户并赋予执行xp-cmdshell权限

GRANT EXECUTE ON sys.xp_cmdshell

    TO Cmd_Login;

 

否则报异常

The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值