Тема: Как посылать сообщения, используя "net send"?

Может кто знает как из VBA посылать сообщения используя net send. Есть ли в API такая возможность? Спасибо.

Re: Как посылать сообщения, используя "net send"?

Вариант 1

Private Declare Function NetMessageBufferSend Lib _
  "NETAPI32.DLL" (yServer As Any, yToName As Byte, _
  yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long
Private Const NERR_Success As Long = 0&
Public Function SendMessageNet(RcptToUser As String, _
   FromUser As String, BodyMessage As String) As Boolean
   Dim RcptTo() As Byte
   Dim From() As Byte
   Dim Body() As Byte
   RcptTo = RcptToUser & vbNullChar
   From = FromUser & vbNullChar
   Body = BodyMessage & vbNullChar
   If NetMessageBufferSend(ByVal 0&, RcptTo(0), ByVal 0&, _
        Body(0), UBound(Body)) = NERR_Success Then
     SendMessageNet = True
   End If
End Function
Private Sub Form_Load()
    Dim RetVal As Boolean
    RetVal = SendMessageNet("Utente", "FromUser", "BodyText")
End Sub

вариант 2 MailSlot

Option Explicit
Private Const OPEN_EXISTING = 3
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const vbDotEveryone As String = "*"
Private Type MailslotMessageData
   sMsgFrom As String
   sSendTo As String
   sMessage As String
End Type
Private Declare Function CreateFile Lib "kernel32" _
   Alias "CreateFileA" _
  (ByVal lpFileName As String, _
   ByVal dwDesiredAccess As Long, _
   ByVal dwShareMode As Long, _
   ByVal lpSecurityAttributes As Long, _
   ByVal dwCreationDisposition As Long, _
   ByVal dwFlagsAndAttributes As Long, _
   ByVal hTemplateFile As Long) As Long
Private Declare Function WriteFile Lib "kernel32" _
  (ByVal hFile As Long, _
   ByVal lpBuffer As Any, _
   ByVal nNumberOfBytesToWrite As Long, _
   lpNumberOfBytesWritten As Long, _
   ByVal lpOverlapped As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
  (ByVal hHandle As Long) As Long
Private Function BroadcastMessage(msg As MailslotMessageData) As String
   Dim hFile As Long
   Dim byteswritten As Long
   Dim buff As String
   Dim sSlotName As String
   If Len(msg.sMessage) = 0 Then
      BroadcastMessage = "No message specified; nothing to do."
      Exit Function
   End If
   If Len(msg.sSendTo) = 0 Then
      msg.sSendTo = vbDotEveryone
   End If
   If Len(msg.sMsgFrom) = 0 Then
      msg.sMsgFrom = "Mailslot System Message"
   End If
   sSlotName = "\\" & msg.sSendTo & "\mailslot\messngr"
   buff = msg.sMsgFrom & vbNullChar & _
          msg.sSendTo & vbNullChar & _
          msg.sMessage & vbNullChar & vbNullChar
   hFile = CreateFile(sSlotName, _
                      GENERIC_WRITE, _
                      FILE_SHARE_READ, _
                      0&, _
                      OPEN_EXISTING, _
                      FILE_ATTRIBUTE_NORMAL, _
                      0&)
   If hFile <> 0 Then
      If WriteFile(hFile, _
                   buff, _
                   Len(buff), _
                   byteswritten, _
                   0) <> 0 Then
         If (Len(buff) = byteswritten) Then
            BroadcastMessage = "The message was successfully sent."
         Else
            BroadcastMessage = "Message sent but bytes written <> message size."
         End If  'If (Len(buff)
      Else
         BroadcastMessage = "Error writing the message."
      End If
      Call CloseHandle(hFile)
    End If  'If hFile
End Function
'вариант вызова
...
   Dim msg As MailslotMessageData
   With msg
      .sMsgFrom = "From"
      .sSendTo = "Destination"
      .sMessage = "Message Body"
   End With
   MsgBox BroadcastMessage(msg)
...

Re: Как посылать сообщения, используя "net send"?

SmeL, спасибо за ответ!
К сожалению, в процессе тестирования выяснилось, что данные вырианты кода работают только в том случае, если в этот момент отключены программы, специально предназначенные для отправки/приёма сообщений в сети (например - LanTalk XP).

Re: Как посылать сообщения, используя "net send"?

str = "net send " + Left(form.Computers.Text, 8) + " " + Trim(my_message.Text)
       my_message.Text = ""
       'str = "net send ws230-1 'test sending' "
       Shell str, vbNormalFocus