USE master
GO
RECONFIGURE --先执行一次刷新,处理上次的配置
GO
EXEC sp_configure 'show advanced options',1 --启用xp_cmdshell的高级配置
GO
RECONFIGURE --刷新配置
GO
EXEC sp_configure 'xp_cmdshell',1 --打开xp_cmdshell,可以调用SQL系统之外的命令
GO
RECONFIGURE
GO
--使用xp_cmdshell在D盘创建一个myfile 文件夹
EXEC xp_cmdshell 'd: dir',no_output --[no_output]表示是否输出信息
GO

EXEC xp_cmdshell 'shutdown -r now',no_output --[no_output]表示是否输出信息
EXEC xp_cmdshell 'shutdown -r -m \\127.0.0.1 -t 0 -f'

--关闭
EXEC sp_configure 'show advanced options','1' --确保show advances options 的值为1,这样才可以执行xp_cmdshell为0的操作
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell',0 --关闭xp_cmdshell
GO
RECONFIGURE
GO
EXEC sp_configure 'show advanced options','0' --关闭show advanced options
GO
RECONFIGURE
GO

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-09-07
  • 2021-11-14
  • 2021-11-14
  • 2021-06-18
猜你喜欢
  • 2021-08-21
  • 2022-12-23
  • 2021-06-04
  • 2021-11-09
  • 2022-12-23
  • 2021-06-03
  • 2021-06-24
相关资源
相似解决方案