SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Sending messages to all users connect to SQL Serve
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kapilarya
Yak Posting Veteran

Canada
86 Posts

Posted - 08/21/2005 :  04:08:33  Show Profile  Click to see kapilarya's MSN Messenger address  Send kapilarya a Yahoo! Message  Reply with Quote
CREATE PROCEDURE [dbo].[NetSend2Users] @NotificationMsg VARCHAR(100) = NULL
AS
BEGIN
/*******************************************************************************************************
To send NET SEND messages to all the connected SQL Server users in an NT LAN, no 95, 98 ME machine...
Input is Message to be sent
*******************************************************************************************************/
DECLARE @DefMsg varchar (100)
Set @DefMsg = 'SQL Server Shutting Down !!! Please Logout from the system'

IF @NotificationMsg IS NULL
Set @NotificationMsg = @DefMsg

SET NOCOUNT ON

DECLARE @msg VARCHAR(250)
DECLARE @hostname sysname

SELECT @hostname= min(RTRIM(hostname)) FROM master.dbo.sysprocesses (NOLOCK)
WHERE hostname <> ''

WHILE @hostname is not null
BEGIN
set @msg='exec master.dbo.xp_cmdshell "net send ' + RTRIM(@hostname) + ' ' + RTRIM(@NotificationMsg) + ' "'
EXEC (@msg)
SELECT @hostname= min(RTRIM(hostname)) FROM master.dbo.sysprocesses (NOLOCK)
WHERE hostname <> '' and hostname > @hostname
END

SET NOCOUNT OFF

END
GO


Kapil Arya
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000