Sending a message to another computer -how?

B

Bob

Vb.net 2005. I need to send a message to a computer named Comp1 on my LAN. I
need window to pop up, much like when a network admin sends a message to
some users that the network will shut down for maintenance. But I need to do
it for one particular computer whose name I know and I need to do it from
within VB.NET 2005 code.
I think I should use the system.messaging namespace but I can't figure out
the sequence. Is there some sample code out there that does this? Looked but
did not find.

Thanks for any help.

Bob
 
C

CMM

If you're looking to send an NT alert to a user (like you describe) and you
know the Alerter/Messenger services (no, not Windows Messenger) are running
on the other computer you can:

1) Use "net send" command:
Process.Start(Environment.GetEnvironmentVariable("COMSPEC"),String.Format("/c
net send {0} \"{1}\"", target, msg));

or

2) Look into using the NetMessageBufferSend API p/invoke. It's very easy to
use:


P.S.
I don't think System.Messaging is at all what you're looking for. That deals
with MSMQ and is not a "messaging" thingy as you know it but rather a way
for applications to send data to each other.
 
G

Guest

you could also use , if your app was on both computers, sockets and network
streams to send and receive text, then display whatever was received in a
Messagebox
 
B

Bob

Thanks, the app is a service that resides on one computer and we don't want
to install anything special on the other computers to keep maintenance task
to a minimum. So I'm leaning towards using the net send command.
 
C

CMM

Check out this code... it encapsulates the NetMessage API so you don't have
to spawn a CommandPrompt to do it. It's actually very very simple:


Imports System.Runtime.InteropServices

Public Class NTAlerter

Private m_sFrom As String = String.Empty
Private m_sBody As String = String.Empty
Private m_sTo As String = String.Empty
Private m_sWhere As String = String.Empty

Private Class Win32

<DllImport("netapi32.dll", CharSet:=CharSet.Unicode)> _
Public Shared Function NetMessageBufferSend(ByVal lpServerName As
String, _
ByVal lpMsgName As String, ByVal lpFromName As String, _
ByVal lpBuf As String, ByVal lnBufLen As Long) As Int32
End Function

End Class

Public Property From() As String
Get
Return m_sFrom
End Get
Set(ByVal Value As String)
m_sFrom = Value
End Set
End Property

Public Property Body() As String
Get
Return m_sBody
End Get
Set(ByVal Value As String)
m_sBody = Value
End Set
End Property

Public Property [To]() As String
Get
Return m_sTo
End Get
Set(ByVal Value As String)
m_sTo = Value
End Set
End Property

Public Property Where() As String
Get
Return m_sWhere
End Get
Set(ByVal Value As String)
m_sWhere = Value
End Set
End Property

Public Function Send() As Integer

Dim sTo As String
Dim sFrom As String
Dim sWhere As String
Dim sBody As String
Dim iResult As Integer

If m_sTo = String.Empty Then
sTo = vbNullString
Else
sTo = m_sTo
End If

If m_sFrom = String.Empty Then
sFrom = vbNullString
Else
sFrom = m_sFrom
End If

If m_sWhere = String.Empty Then
sWhere = vbNullString
Else
sWhere = m_sWhere
End If

If m_sBody.Length > 0 And m_sTo.Length > 0 Then
sBody = Left(m_sBody, 255)
iResult = Win32.NetMessageBufferSend(sWhere, sTo, sFrom, sBody,
sBody.Length * 2)
Return iResult
End If

End Function

End Class
 
B

Bob

Thanks, I"ll give it a shot
Bob

CMM said:
Check out this code... it encapsulates the NetMessage API so you don't
have to spawn a CommandPrompt to do it. It's actually very very simple:


Imports System.Runtime.InteropServices

Public Class NTAlerter

Private m_sFrom As String = String.Empty
Private m_sBody As String = String.Empty
Private m_sTo As String = String.Empty
Private m_sWhere As String = String.Empty

Private Class Win32

<DllImport("netapi32.dll", CharSet:=CharSet.Unicode)> _
Public Shared Function NetMessageBufferSend(ByVal lpServerName As
String, _
ByVal lpMsgName As String, ByVal lpFromName As String, _
ByVal lpBuf As String, ByVal lnBufLen As Long) As Int32
End Function

End Class

Public Property From() As String
Get
Return m_sFrom
End Get
Set(ByVal Value As String)
m_sFrom = Value
End Set
End Property

Public Property Body() As String
Get
Return m_sBody
End Get
Set(ByVal Value As String)
m_sBody = Value
End Set
End Property

Public Property [To]() As String
Get
Return m_sTo
End Get
Set(ByVal Value As String)
m_sTo = Value
End Set
End Property

Public Property Where() As String
Get
Return m_sWhere
End Get
Set(ByVal Value As String)
m_sWhere = Value
End Set
End Property

Public Function Send() As Integer

Dim sTo As String
Dim sFrom As String
Dim sWhere As String
Dim sBody As String
Dim iResult As Integer

If m_sTo = String.Empty Then
sTo = vbNullString
Else
sTo = m_sTo
End If

If m_sFrom = String.Empty Then
sFrom = vbNullString
Else
sFrom = m_sFrom
End If

If m_sWhere = String.Empty Then
sWhere = vbNullString
Else
sWhere = m_sWhere
End If

If m_sBody.Length > 0 And m_sTo.Length > 0 Then
sBody = Left(m_sBody, 255)
iResult = Win32.NetMessageBufferSend(sWhere, sTo, sFrom, sBody,
sBody.Length * 2)
Return iResult
End If

End Function

End Class




Bob said:
Thanks, the app is a service that resides on one computer and we don't
want to install anything special on the other computers to keep
maintenance task to a minimum. So I'm leaning towards using the net send
command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top