Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Winpoup messages

Posted on 1998-11-25
Medium Priority
Last Modified: 2012-08-14
I'm using winpoup as my sender messages program. However I cannot pass parameters to it from a command line. So I'm interest in another application or even bulding, using VB6, an application like a winpoup to send messages on network, which I will be able to pass parameters, like the username and the message.

Could You help me to indicate some steps, like a :Which API should I use, Which commands, and some parts of program that I have to build ?
Question by:MVianna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2

Author Comment

ID: 1446738
Edited text of question

Author Comment

ID: 1446739
Edited text of question

Author Comment

ID: 1446740
I will use this program with other program in FOX, that sends its messages to my machine, which is not the same where the Fox application runs.

This problem happened when my network has changed from Netware to NT. I use to write programs using the SEND Netware command with the Fox statment RUN /N. However Windows 95 under NT  doesn't have this function. I've done a litle research and I saw that the NT server has the NET SEND command, but I need the same NET SEND command on each station, and according our expertises here, we haven't this command available to WIN 95. So I thought in use the winpoup, which use to be our normal exchange-messages application. But I'm not able to pass parameter as an username and message from a command line as a statment.

That's when I thought in build an application with VB6 and some API who I would call a network service.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 14

Expert Comment

ID: 1446741
Here is a class to send message to winpopup

' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         :
' * E-Mail           :
' * Date             : 5/10/98
' * Time             : 15:28
' * Module Name      : class_NetSend
' * Module Filename  : NetSend.cls
' **********************************************************************
' * Comments         :
' * By: Perry Harmon
' *
' *
' * Requires VB5 and NT 4.0
' * Sends message from NT 4.0 to NT 4.0 or Win95 running winpopup
' *
' Properties:
'   SendTo - Read/Write
'   SendFromServer - Read/Write
'   Message - Read/Write
'   Err - Read Only
'   ErrorText - Read Only
' Methods:
'   NetSendMessage - Boolean Returns True/False (Success/Failure)
'       optional parameters:
'           sUser ' String - Message Recipient
'           sMsg  ' String - Message Text
'   ClearError - Sets object.Err = 0, object.ErrorText = ""
' Events:
'   Error - raised on error
'       parameters:
'           lError ' Error Code
'           ErrorText ' Just That
'   Sent - raised when object.NetSendMessage executed without errors
'       parameters: None
'**** Example  ******
' Add to Form Declarations Section
' Private WithEvents mNetSend As clsNetSend
' Add to a procedure/function
' Set mNetSend = New clsNetSend
' With mNetSend
'    .Message = "Your Message Here"
'    .SendTo = "UserNameOrWorkStation"
'    .SendFromServer = "ServerOrWorkStation" 'This is optional
'    .NetSendMessage ' Send the message
' End With

' Private Sub mNetSend_Error(ByVal lError As Long, ByVal ErrorText As String)
'    Debug.Print lError & " - " & ErrorText
' End Sub

' Private Sub mNetSend_Sent()
'    debug.print "Message Sent"
' End Sub
'**** Example  ******
' Private mNetSend As New clsNetSend
' Dim bSuccess As Boolean
' If mNetSend.NetSendMessage("UserOrWorkstationName", "This Is A Test") Then
'   MsgBox "Message Sent"
' else
'   MsgBox "Error " & mNetSend.Err & " - " & mNetSend.ErrorText
' End If
' Broadcast a message to all members of Domain called DomainName
' bSuccess = mNetSend.NetSendMessage("DomainName*", "This Is A Test")
' **********************************************************************

Option Explicit

Private Const ERROR_ACCESS_DENIED = 5&
Private Const ERROR_BAD_NETPATH = 53&
Private Const ERROR_NOT_SUPPORTED = 50&
Private Const ERROR_INVALID_NAME = 123&
Private Const NERR_Success = 0&       ' Success
Private Const NERR_NameNotFound = 2273& ' The message alias could not be found on the network.
Private Const NERR_NetworkError = 2136& ' A general network error occurred.

Private Declare Function NetSend Lib "Netapi32" Alias "NetMessageBufferSend" (ByVal cServerName As String, ByVal cMsgName As String, ByVal cFromName As String, ByVal cBuf As String, ByRef iBufLen As Integer) As Integer
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Private Const VER_PLATFORM_WIN32_NT = 2

   dwOSVersionInfoSize  As Long
   dwMajorVersion       As Long
   dwMinorVersion       As Long
   dwBuildNumber        As Long
   dwPlatformId         As Long
   szCSDVersion         As String * 128      '  Maintenance string for PSS usage
End Type

' Events
Public Event Error(ByVal lError As Long, ByVal ErrorText As String)
Public Event Sent()

' Local copies of properties
Private m_sMsgTo As String
Private m_sMsg As String
Private m_sMsgFrom As String
Private m_lNetApiStatus As Long
Private m_sErrorText As String
Private m_bIsWinNT As Boolean

Function IsWindowsNT() As Boolean
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         :
   ' * E-Mail           :
   ' * Date             : 5/10/98
   ' * Time             : 15:30
   ' * Module Name      : class_NetSend
   ' * Module Filename  : D:\TWA\NetSend\NetSend.cls
   ' * Procedure Name   : IsWindowsNT
   ' * Parameters       :
   ' **********************************************************************
   ' * Comments         : Returns true if this program is running under Windows NT
   ' *
   ' *
   ' **********************************************************************

   Dim lRC        As Long

   typOSInfo.dwOSVersionInfoSize = Len(typOSInfo)
   lRC = GetVersionEx(typOSInfo)
   IsWindowsNT = (typOSInfo.dwPlatformId = VER_PLATFORM_WIN32_NT)

End Function

Public Sub ClearError()
   ' Set Error Properties
   m_lNetApiStatus = 0
   m_sErrorText = ""

End Sub

Public Property Get ErrorText() As String
   'Set ErrorText
   ErrorText = m_sErrorText

End Property

Public Property Get Err() As Long
   ' Set Error Number
   Err = m_lNetApiStatus

End Property

Private Function SetErrorText(Error As Long) As String
   Select Case Error
      Case ERROR_ACCESS_DENIED: SetErrorText = "Access Denied!"
      Case ERROR_BAD_NETPATH: SetErrorText = "Server '" & UCase$(m_sMsgFrom) & "' not Found."
      Case ERROR_INVALID_PARAMETER: SetErrorText = "Invalid parameter specified."
      Case ERROR_NOT_SUPPORTED: SetErrorText = "Network request not supported."
      Case ERROR_INVALID_NAME: SetErrorText = "Illegal character or malformed name."
      Case NERR_Success: SetErrorText = "Message sent."
      Case NERR_NameNotFound: SetErrorText = "User/Workstation '" & m_sMsgTo & "' not found."
      Case NERR_NetworkError: SetErrorText = "General network error occurred."
      Case Else: SetErrorText = "Unknown error executing command."
   End Select

End Function

Private Sub SetLastErr(ByVal lError As Long)
   m_lNetApiStatus = lError
   m_sErrorText = SetErrorText(lError)
   If m_lNetApiStatus Then RaiseEvent Error(m_lNetApiStatus, m_sErrorText)

End Sub
Public Function NetSendMessage(Optional ByVal sUser As String = "", Optional ByVal sMsg As String = "") As Boolean

   Dim sBuf             As String
   Dim sMsgFrom         As String
   Dim sMsgName         As String
   Dim Net_Api_Status   As Long

   If Not m_bIsWinNT Then Exit Function

   If Len(sUser) Then m_sMsgTo = sUser ' Else use the SendTo Property

   If m_sMsgTo = "" Then
      NetSendMessage = False
      RaiseEvent Error(ERROR_INVALID_PARAMETER, m_sErrorText)
      Screen.MousePointer = vbHourglass

      If Len(sMsg) Then m_sMsg = sMsg

      sBuf = StrConv(m_sMsg, vbUnicode)
      sMsgName = StrConv(m_sMsgTo, vbUnicode)

      If Len(m_sMsgFrom) And sUser = "" Then
         sMsgFrom = StrConv(m_sMsgFrom, vbUnicode)
         sMsgFrom = vbNullString
      End If
      Net_Api_Status = NetSend(sMsgFrom, sMsgName, vbNullString, sBuf, ByVal Len(sBuf))
      SetLastErr Net_Api_Status
      NetSendMessage = Not CBool(Net_Api_Status)
      If NetSendMessage Then RaiseEvent Sent
      Screen.MousePointer = vbNormal
   End If

End Function

Public Property Let Message(ByVal vData As String)
   'used when assigning a value to the property, on the left side of an assignment.
   'Syntax: X.sMessage = 5
   m_sMsg = vData

End Property

Public Property Get Message() As String
   'used when retrieving value of a property, on the right side of an assignment.
   'Syntax: Debug.Print X.sMessage
   Message = m_sMsg

End Property

Public Property Let SendTo(ByVal vData As String)
   m_sMsgTo = vData

End Property

Public Property Get SendTo() As String
   SendTo = m_sMsgTo

End Property

Public Property Let SendFromServer(ByVal vData As String)
   'used when assigning a value to the property, on the left side of an assignment.
   m_sMsgFrom = vData

End Property

Public Property Get SendFromServer() As String
   'used when retrieving value of a property, on the right side of an assignment.
   SendFromServer = m_sMsgFrom

End Property

Private Sub Class_Initialize()
   m_bIsWinNT = IsWindowsNT()
   If m_bIsWinNT Then
      m_lNetApiStatus = 0
      MsgBox "The NetSend class requires Windows NT.", vbCritical + vbOKOnly, "Net Send"
   End If

End Sub


Author Comment

ID: 1446742
Unfortunately Waty's proposed answer using : NT to NT or Win 95,and I appreciate the code, it's very interesting, however I need something different,I need to send messages from Win 95 to win 95 or NT.

Waty, thank for your prompt reply.


Accepted Solution

gencross earned 400 total points
ID: 1446743
To create an application like WinPopup you will use mailslots just like WinPopup does.  Here is some information on mailslots, the api's you have to use and some code, somewhat like waty's, but much simpler, that will send a message to winpopup running on a machine.

Mailslots are.....

A pipe forms a direct connection between two processes. A mailslot can best be thought of as somewhat like the U.S. Postal Service. You can send messages from many different locations that are all addressed to the same mailbox, but you can’t be absolutely certain that they will all arrive safely.
An application establishes a mailslot on its own system with a unique name. The name takes the form “
\\.\mailslot\path\mailslotname.” The server application (the one that creates the mailslot) can only create it on its own system, but client applications can write to mailslots throughout their domain. A mailslot name can have a pseudo path, for example, \\.\mailslot\ desaware\user\marketing. This path does not correspond to any real path on a file system—it is merely a handy way to categorize mailslots into groups.

When a client opens a mailslot using the CreateFile function, it can use “\\.\mailslot\...” if the client and the server are running on the same system, “\\computername\mailslot\...” to open a mailslot on a remote system, or “
\\domainname\mailslot\...” to open every mailslot with the specified name on the specified domain (use “*” for the domain name to specify the primary domain). The client should specify (FILE_SHARE_READ or FILE_SHARE_WRITE) for the file-sharing mode when using mailslots so that more than one client can write to the same server.

Multiple clients can open the same mailslot, in which case each client can write to the mailslot at will—the server will read messages from every client. When a client is connected to multiple mailslots, each active server will receive the message that it sends. Mailslot handles can be duplicated and shared among servers. The DuplicateHandle function can also be used.

Here are the api's, type, and constants that you will need...

        Internal As Long
        InternalHigh As Long
        offset As Long
        OffsetHigh As Long
        hEvent As Long
End Type

Private Declare Function CreateMailslot Lib "kernel32" Alias "CreateMailslotA" (ByVal lpName As String, ByVal nMaxMessageSize As Long, ByVal lReadTimeout As Long, ByVal lpSecurityAttributes As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function ReadFileAsync Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As OVERLAPPED) As Long
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 GetLastError Lib "kernel32" () As Long
Private Const OPEN_EXISTING = 3
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const GENERIC_EXECUTE = &H20000000
Private Const GENERIC_ALL = &H10000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2

Sample code to send a message.  It will show you have to use the mailslots api's (some of them).  Once you understand the way mailslots work you can figure them out.  They are really not that hard to understand.

Global Const OPEN_EXISTING = 3
Global Const GENERIC_READ = &H80000000
Global Const GENERIC_WRITE = &H40000000
Global Const GENERIC_EXECUTE = &H20000000
Global Const GENERIC_ALL = &H10000000
Global Const FILE_SHARE_READ = &H1
Global Const FILE_SHARE_WRITE = &H2

Declare Function CloseHandle Lib "kernel32" (ByVal hHandle As Long) As Long

Declare Function WriteFile Lib "kernel32" (ByVal hFileName As Long, ByVal lpBuff As Any, ByVal nNrBytesToWrite As Long, lpNrOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwAccess As Long, ByVal dwShare As Long, ByVal lpSecurityAttrib As Long, ByVal dwCreationDisp As Long, ByVal dwAttributes As Long, ByVal hTemplateFile As Long) As Long

Function SendToWinPopUp(PopFrom As String, PopTo As String, MsgText As String) As Long

        Dim rc As Long
        Dim mshandle As Long
        Dim msgtxt As String
        Dim byteswritten As Long
        Dim mailslotname As String
       '      ' name of the mailslot
        mailslotname = "\\" + PopTo + "\mailslot\messngr"
        msgtxt = PopFrom + Chr(0) + PopTo + Chr(0) + MsgText + Chr(0)
        mshandle = CreateFile(mailslotname, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
        rc = WriteFile(mshandle, msgtxt, Len(msgtxt), byteswritten, 0)
        rc = CloseHandle(mshandle)
End Function

Private Sub Command1_Click()

        SendToWinPopUp txtFrom, txtTo, txtMsg
End Sub

I hope this helps.

Expert Comment

ID: 1446744
I forget to tell you that the sample code I provided will send a message to Winpopup.  It will help you get an understanding of how mailslots work.
LVL 14

Expert Comment

ID: 1446745
Sure, mailslot is your solution, or otherwise, communication with simple files. I use files to communicate between some process (some of them are running on NT, other under Unix). Files is the more large easy way to implement a process communication, without any technology, and with any language.

Author Comment

ID: 1446746
Thank waty, you've agreed. I'm sure i'll have some problems to implement it on my network, but let's do it. If I some problem appear, I would aprreciate your help and also gencross.

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question