Check this: http://msdn.microsoft.com/en-us/library/ms175046.aspx
**B. Using Windows net commands**
The following example shows the use of xp_cmdshell in a stored procedure. This example notifies users by using net send that an instance of SQL Server is about to be shut down, pauses the server by using net pause, and then shuts the server down by using 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
↧