create proc p_sendmsg
@msg nvarchar(1000) --要发送的信息内容
as
declare @s nvarchar(4000)
set @msg=replace(isnull(@msg,''),'"','""')
declare tb cursor local for
select distinct 'net send "'+rtrim(hostname)+'" "'+@msg+'"'
from sysprocesses where hostname<>''
open tb
fetch tb into @s
begin
exec master..xp_cmdshell @s,no_output
print @s
fetch tb into @s
end
close tb
deallocate tb
go