Home All Groups Group Topic Archive Search About

Sending a message to another computer -how?

Author
30 Jan 2006 9:40 PM
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

Author
31 Jan 2006 6:43 AM
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.



Show quoteHide quote
"Bob" <bduf***@sgiims.com> wrote in message
news:exQhXXeJGHA.3912@TK2MSFTNGP10.phx.gbl...
> 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
>
>
Author
31 Jan 2006 4:40 PM
iwdu15
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
--
-iwdu15
Author
31 Jan 2006 7:36 PM
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.


Show quoteHide quote
"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:C315FD25-4222-4ED8-9682-29306E062F9F@microsoft.com...
> 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
> --
> -iwdu15
Author
31 Jan 2006 7:53 PM
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




Show quoteHide quote
"Bob" <bduf***@sgiims.com> wrote in message
news:%23gvKn6pJGHA.524@TK2MSFTNGP09.phx.gbl...
> 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.
>
>
> "iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
> news:C315FD25-4222-4ED8-9682-29306E062F9F@microsoft.com...
>> 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
>> --
>> -iwdu15
>
>
Author
2 Feb 2006 7:38 PM
Bob
Thanks, I"ll give it a shot
Bob

Show quoteHide quote
"CMM" <cmm@nospam.com> wrote in message
news:%23F%23I3$pJGHA.1424@TK2MSFTNGP12.phx.gbl...
> 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" <bduf***@sgiims.com> wrote in message
> news:%23gvKn6pJGHA.524@TK2MSFTNGP09.phx.gbl...
>> 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.
>>
>>
>> "iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
>> news:C315FD25-4222-4ED8-9682-29306E062F9F@microsoft.com...
>>> 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
>>> --
>>> -iwdu15
>>
>>
>
>