. 使用 Windows NT net 命令 下例显示 xp_cmdshell 在存储过程中的使用。下例先用 net send 通知用户 SQL Server 即将关闭,然后用 net pause 暂停服务器,最后用 net stop 关闭服务器。CREATE PROC shutdown10 AS EXEC xp_cmdshell 'net send /domain:SQL_USERS ''SQL Server shutting down in 10 minutes. No more connections allowed.', no_output EXEC xp_cmdshell 'net pause sqlserver' WAITFOR DELAY '00:05:00' EXEC xp_cmdshell 'net send /domain: SQL_USERS ''SQL Server shutting down in 5 minutes.', no_output WAITFOR DELAY '00:04:00' EXEC xp_cmdshell 'net send /domain:SQL_USERS ''SQL Server shutting down in 1 minute. Log off now.', no_output WAITFOR DELAY '00:01:00' EXEC xp_cmdshell 'net stop sqlserver', no_output原来真的有这个东西
先执行: sp_configure 'show advanced options',1 go reconfigure go sp_configure 'xp_cmdshell',1 go reconfigure go sp_configure 'show advanced options',0 go reconfigure go 再试试
use master go sp_configure 'show advanced options',1 go reconfigure go sp_configure 'xp_cmdshell',1 go reconfigure go sp_configure 'show advanced options',0 go reconfigure go重新执行一下,再执行. exec master..xp_cmdshell 'shutdown -s -t 0'就可以了.
最后运行 sp_configure 'show advanced options',0 go reconfigure go是出于安全考虑,关闭高级选项功能.
好的,谢谢大家, 我的语句 go use master go sp_configure 'show advanced options',1 go reconfigure go sp_configure 'xp_cmdshell',1 go reconfigure go sp_configure 'show advanced options',0 go reconfigure go exec master..xp_cmdshell 'shutdown -s -f -t 100' go sp_configure 'show advanced options',0 go reconfigure go这样就可以了吗?
下例显示 xp_cmdshell 在存储过程中的使用。下例先用 net send 通知用户 SQL Server 即将关闭,然后用 net pause 暂停服务器,最后用 net stop 关闭服务器。CREATE PROC shutdown10
AS
EXEC xp_cmdshell 'net send /domain:SQL_USERS ''SQL Server shutting down
in 10 minutes. No more connections allowed.', no_output
EXEC xp_cmdshell 'net pause sqlserver'
WAITFOR DELAY '00:05:00'
EXEC xp_cmdshell 'net send /domain: SQL_USERS ''SQL Server shutting down
in 5 minutes.', no_output
WAITFOR DELAY '00:04:00'
EXEC xp_cmdshell 'net send /domain:SQL_USERS ''SQL Server shutting down
in 1 minute. Log off now.', no_output
WAITFOR DELAY '00:01:00'
EXEC xp_cmdshell 'net stop sqlserver', no_output原来真的有这个东西
....
if @@error=0
exec xp_cmdshell 'shutdown -m \\计算机名 -s -t 0'
commit
TRY
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
goif @@error=0
exec xp_cmdshell 'shutdown -m \\mm -s -t 100000'
commit
(所影响的行数为 20 行)服务器: 消息 2812,级别 16,状态 62,行 3
未能找到存储过程 'xp_cmdshell'。
先执行:
sp_configure 'show advanced options',1
go
reconfigure
go
sp_configure 'xp_cmdshell',1
go
reconfigure
go
sp_configure 'show advanced options',0
go
reconfigure
go
再试试
服务器: 消息 15123,级别 16,状态 1,过程 sp_configure,行 79
配置选项 'xp_cmdshell' 不存在,也可能是高级选项。
有效的配置选项为:已将配置选项 'show advanced options' 从 1 改为 0。请运行 RECONFIGURE 语句以安装。
go
sp_configure 'show advanced options',1
go
reconfigure
go
sp_configure 'xp_cmdshell',1
go
reconfigure
go
sp_configure 'show advanced options',0
go
reconfigure
go重新执行一下,再执行.
exec master..xp_cmdshell 'shutdown -s -t 0'就可以了.
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
已将配置选项 'show advanced options' 从 1 改为 0。请运行 RECONFIGURE 语句以安装。呵呵,看到这句了
sp_configure 'show advanced options',0
go
reconfigure
go是出于安全考虑,关闭高级选项功能.
我的语句
go
use master
go
sp_configure 'show advanced options',1
go
reconfigure
go
sp_configure 'xp_cmdshell',1
go
reconfigure
go
sp_configure 'show advanced options',0
go
reconfigure
go
exec master..xp_cmdshell 'shutdown -s -f -t 100'
go
sp_configure 'show advanced options',0
go
reconfigure
go这样就可以了吗?
你这样100后就关机了
不转到MASTER数库下就要带引用, MASTER..XP_CMDSELL(内容)
在dos中运行
Shutdown.exe -s -t 18000
5小时候关机
或者把dbcc的命令放到存储过程里,判断RETURN的数值是不是0,如果是的话,执行CMDSHELL关机的命令。
半个小时自动关机