0 Replies - 1676 Views - Last Post: 28 July 2008 - 02:31 AM

#1 dineeshd   User is offline

  • member icon

Reputation: 39
  • View blog
  • Posts: 619
  • Joined: 30-June 08

MSSQL Snippet to send Message in LAN

Posted 28 July 2008 - 02:31 AM

Description: Usage : Pr_NetSend 'Hello World'This snippet can be handy to send "net send" messages in LAN
IF EXISTS (SELECT NAME FROM sysobjects WHERE NAME = 'Pr_NetSend' AND type = 'P')
	DROP PROCEDURE Pr_NetSend
GO

CREATE PROCEDURE Pr_NetSend
	@in_msg varchar(200)
AS
BEGIN

	SET NOCOUNT ON
	
	DECLARE @SystemName SYSNAME
	DECLARE @NetSendMsg VARCHAR(250)
	
	SELECT @SystemName = MIN(RTRIM(HOSTNAME)) FROM master.dbo.sysprocesses (NOLOCK) WHERE HOSTNAME <> ''
	 
	WHILE @SystemName IS NOT NULL
	BEGIN
		SET @NetSendMsg = 'EXEC master.dbo.xp_cmdshell "NET SEND ' + RTRIM(@SystemName) + ' ' + RTRIM(@in_msg) + ' "'
		
	        EXEC (@NetSendMsg)
	        
	  	SELECT @SystemName = MIN(RTRIM(hostname)) FROM master.dbo.sysprocesses (NOLOCK)
	  	WHERE HOSTNAME <> '' AND HOSTNAME > @SystemName
	END
	
	SET NOCOUNT OFF

END
GO



Is This A Good Question/Topic? 0
  • +

Page 1 of 1