No announcement yet.

NetMessageBufferSend: "User/wrkstation not found"

  • Filter
  • Time
  • Show
Clear All
new posts

    NetMessageBufferSend: "User/wrkstation not found"


    I'm just beginning with PB/DLL, so it could be sthing obvious, but I'm at a total loss: I'd like to use the NetMessageBufferSend API to perform the equivalent of DOS' net send, ie. send a message to a host.

    Declare FUNCTION NetMessageBufferSend LIB "NETAPI32.DLL" ALIAS "NetMessageBufferSend" (server AS ASCIIZ, receiver AS ASCIIZ, sender AS ASCIIZ, msg AS ASCIIZ, BYVAL msglen AS LONG) AS LONG

    LOCAL sServer AS ASCIIZ * 64
    LOCAL sTo AS ASCIIZ * 64
    LOCAL sFrom AS ASCIIZ * 64
    LOCAL lpBuffer AS ASCIIZ * 255
    LOCAL slength As Long
    LOCAL lResult AS LONG

    sServer = ""
    sTo = "W2K"
    sFrom = "W2K"
    lpBuffer ="Test"
    sLength = Len(lpBuffer)
    lResult = NetMessageBufferSend (sServer, sTo, sFrom, lpBuffer, sLength)

    <B>=> "User or workstation was not found"</B>

    FYI, net send w2k "This is a test" works. Both the Msg Browser and Computer Browser services run.

    1. Could it be a Unicode issue?
    2. What's the difference between the first two parameters (server on which the function will run, name to which the msg will be sent)?

    Thx much for any tip


    As far as I know, "sFrom" must be the username. Not the computer name.

    E-Mail (home): mailto:[email protected][email protected]</A>
    E-Mail (work): mailto:[email protected][email protected]</A>


      Originally posted by Sven Blumenstein:
      As far as I know, "sFrom" must be the username. Not the computer name.

      Thx for the tip, but here's what it says in the WIN32 Programmer's Ref:

      Pointer to a Unicode string containing the message name sending the information. The fromname parameter is new for Windows networking. This parameter is needed for sending interrupting messages from the computer name rather than the logged on user. If NULL is specified, the message is sent from the logged-on user as with LAN Manager 2.x."




        This works fine on my PC under Win2000.
           #Compile Exe
           #Dim All
           #Register None
           #Include "Win32Api.Inc"
           $Server  = ""
           $From    = "Semen"
           $To      = "Su*"   ' <--- Change to your domainname & "*"  or computer name (w/o *)
           $Msg   = "This is a test message"
           Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" Alias "NetMessageBufferSend" _
              (ByVal Long, ByVal Long, ByVal Long, ByVal Long, ByVal Long) As Long
           Function UnicodeString (AsciiString As String) As Long
              Static nUnicodeStrings As Long, mUnicodeStrings As Long
              If nUnicodeStrings >= mUnicodeStrings Then _
                 mUnicodeStrings = Max(mUnicodeStrings, 100) * 2: ReDim Preserve UnicodeStrings(mUnicodeStrings - 1) As Static String
              UnicodeStrings(nUnicodeStrings) = Space$(Len(AsciiString) * 2)
              MultiByteToWideChar ByVal %CP_ACP, ByVal 0&, ByVal StrPtr(AsciiString), _
                 ByVal -1, ByVal StrPtr(UnicodeStrings(nUnicodeStrings)), ByVal Len(AsciiString)
              Function = StrPtr(UnicodeStrings(nUnicodeStrings))
              Incr nUnicodeStrings
           End Function
           Function PbMain
              NetMessageBufferSend UnicodeString($Server), UnicodeString($To), UnicodeString($From), UnicodeString($Msg), Len($Msg) * 2
           End Function

        E-MAIL: [email protected]


          Finally got it working! Turns out that my code in PowerBasic handled strings as ANSI, so you have to use MultiByteToWideChar to convert from ANSI to UNICODE because NetMessageBufferSend() only works with Unicode.

          Also, watch out for the SetWindowText() defined in WIN32API.INC: It's the ANSI version, so will only display the first character when used with a UNICODE string (I was using this to test conversion.)

          Finally, do not use len(strUnicode): len() only works in ANSI, so will also stop after the first character.

          Quite a lot of investigation for my first step working with PB/DLL

          $INCLUDE "WIN32API.INC"
          %STR_MAX_SIZE 64
          Declare FUNCTION NetMessageBufferSend LIB "NETAPI32.DLL" ALIAS "NetMessageBufferSend" (sServer AS ASCIIZ, _
          	sTo AS ASCIIZ, sFrom AS ASCIIZ, sMsg AS ASCIIZ, BYVAL msglen AS LONG) AS LONG
          Declare Function SetWindowTextW Lib "user32.dll" ALIAS "SetWindowTextW" (BYVAL hwnd AS LONG, sText AS ASCIIZ) AS LONG
          LOCAL lResult	  AS LONG
          LOCAL sToHostA as ASCIIZ * %STR_MAX_SIZE
          LOCAL sToHostW as ASCIIZ * (%STR_MAX_SIZE * 2)
          sToHostA = "W2K"
          LOCAL sBufferA AS ASCIIZ * %STR_MAX_SIZE
          LOCAL sBufferW AS ASCIIZ * (%STR_MAX_SIZE * 2)
          sBufferA = "All your base are belong to us"
          lResult = MultiByteToWideChar (%CP_ACP, 0&, sToHostA, -1, sToHostW, Len(sToHostA) * 2)
          lResult = MultiByteToWideChar (%CP_ACP, 0&, sBufferA, -1, sBufferW, Len(sBufferA) * 2)
          lResult = NetMessageBufferSend ("", sToHostW, "", sBufferW, %STR_MAX_SIZE * 2)
          Thx to everyone for the tips!

          [This message has been edited by Frederic Faure (edited July 06, 2001).]