Solved

NetMessageBufferSend & Net_API_Status

Posted on 1997-05-09
10
1,021 Views
Last Modified: 2011-10-03
I'm trying to figure out how to do a LAN Manager type "net send" using the NetMessageBufferSend API in vb4. I'm missing something (code below).

1. What's the right declare? I can't find a declare for this function in the api text files.

2. The function returns a value "Net_API_Status", a dword, but I can't find any documentation that tells me what the return values mean. In the code below, NetMessageBufferSend is returning 123.

Can anybody smarter than me help?

Here's the code:

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
Sub main()
    Dim Net_API_Status As Integer
    Dim cBuf As String * 255
    Dim cNull As String * 1
    Dim cMsgName As String
    cNull = ""
    cBuf = "Hello, world!"
    cMsgName = StrConv("gmccull", vbUnicode)
    Net_API_Status = NetSend(cNull, cMsgName, cNull, cBuf, 255)
    MsgBox (Str(Net_API_Status))
End Sub

And, to save you the trouble of looking it up, here's some documentation from MSDN:

NetMessageBufferSend sends a buffer of information to a registered message alias.
Security Requirements
No special group membership is required to execute NetMessage buffer send locally. Admin, accounts, print, or server operator group membership is required to successfully execute NetMessageBufferSend on a remote server.
NET_API_STATUS
NetMessageBufferSend (
 

    LPTSTR servername,      
    LPTSTR msgname,      
    LPTSTR fromname,      
    LPBYTE buf,      
    DWORD buflen      
   );      
Parameters
servername
A pointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.
msgname
A pointer to a Unicode string containing the message name to which the message buffer should be sent.
fromname
A pointer to a Unicode string containing the message name sending the information. fromname is a new parameter for Windows networking. This parameter is needed for sending alerts from the computer name rather than the logged on user. If a NULL is specified the message is send from the logged on user as with LAN Manager 2.x.
buf
A pointer to a buffer of message text.
buflen
The length in bytes of the message text in buf.
0
Comment
Question by:gmccull
  • 5
  • 3
  • 2
10 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1426134
From what I can tell as you say NET_API_STATUS is a DWORD which equates to a Long not a Integer.  I would expect this value to simply be 1 since in Visual C/C++ it simply defined as follows:

#define NET_API_STATUS      DWORD

Other than this in the Visual C/C++ Online help I can not find anymore information on the function than this below (it seems like they left off what the function actually returns since they say it can basically return a long):


The NetMessageBufferSend function sends a buffer of information to a registered message alias.
Security Requirements
No special group membership is required to execute NetMessageBufferSend on a LAN Manager or Windows NT system. Admin, Accounts, Print, or Server operator group membership is required to successfully execute NetMessageBufferSend on a remote server.
NET_API_STATUS NetMessageBufferSend(
    LPTSTR servername,      
    LPTSTR msgname,      
    LPTSTR fromname,      
    LPBYTE buf,      
    DWORD buflen      
   );      
 
Parameters
servername
Pointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.
msgname
Pointer to a Unicode string containing the message name to which the message buffer should be sent.
fromname
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.
buf
Pointer to a buffer of message text.
buflen
The length, in bytes, of the message text in buf.



0
 

Author Comment

by:gmccull
ID: 1426135
This does not address my question at all. The only piece of information added is that a DWORD is a LONG not an INTEGER. The documentation quoted is already quoted in my own question. Neither of the two queries I put are addressed: 1. What is the correct declare in VB for this API call? and 2. What do the return values mean?
0
 
LVL 7

Expert Comment

by:tward
ID: 1426136
Sorry about that...
I would change the following:
*****************************************
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

Sub main()
Dim Net_API_Status As Integer
Dim cBuf As String * 255
Dim cNull As String * 1
Dim cMsgName As String
cNull = ""
cBuf = "Hello, world!"
cMsgName = StrConv("gmccull", vbUnicode)
Net_API_Status = NetSend(cNull, cMsgName, cNull, cBuf, 255)
MsgBox (Str(Net_API_Status))
End Sub
****** TO ****
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 Long) _
As Long

Sub main()
Dim Net_API_Status As Long
Dim cBuf As String
Dim cMsgName As String

cmsgName = String$(255,0)
cBuf = "Hello, world!"  & vbNullChar

Net_API_Status = NetSend(0&, cMsgName, cNull, cBuf, 255)
MsgBox (Str(Net_API_Status))
End Sub

If I find anything out about the returnvalue I will post it but for now I can not find anything other than it returns a long value!
0
 

Author Comment

by:gmccull
ID: 1426137
Well, that begins to get a little closer, but it's not working yet. I've incorporated your changes, see the code attached. I still do not get a "net send", but the error has changed. Now I get "53". Some modifications of this code return "2273". I suspect that these numbers are actually net.exe errorcodes. You can do a "net helpmsg <nnnn>" on these values. For example, "net helpmsg 53" gives: "The network path was not found." and 2273 gives: "The message alias could not be found on the network...."

Couple of notes:

1. I do a unicode string conversion because the NetMessageBufferSend documentation says it wants its strings as unicode strings. Is this conversion necessary? (I get the same return code either way.)

2. To test the code, cMsgName needs to be a valid computername or username on the network. (cBuf is the message text being sent to cMsgName.)

Here's my code incorporating your changes, along with the comments above:

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 Long) _
  As Long

Sub main()

Dim iNet_API_Status As Long
Dim cBuf As String
Dim cMsgName As String

cMsgName = String$(14, 0)
cMsgName = StrConv("gmccull", vbUnicode)
cMsgName = cMsgName + vbNullChar

cBuf = String$(255, 0)
cBuf = "Hello, world!" + vbNullChar

iNet_API_Status = NetSend(vbNull, cMsgName, vbNull, cBuf, 255)
MsgBox (Str(iNet_API_Status))

End Sub
0
 
LVL 7

Expert Comment

by:tward
ID: 1426138
Another look into the Visual C/C++ 4.2 at that function says that it is for Windows NT.  They give a quickinfo button that says No under Win95 and Win32s but Yes under Windows NT.

Are you using Windows NT?  If so then reject this answer...  otherwise I have no other ideas for you at this time.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:gmccull
ID: 1426139
I ought to have pointed out that this little app is intended for NT machines. I feel like I must be pretty close to getting it to work, but that one or  more arguments are not being passed correctly to the API function.
0
 
LVL 5

Accepted Solution

by:
y96andha earned 100 total points
ID: 1426140
I have got it working, just tested it a couple of times. This is the code you should use.

Private Declare Function NetSend _
Lib "netapi32" _
Alias "NetMessageBufferSend" _
(ByVal cServerName As String, _
ByVal cMsgName As String, _
ByVal cFromName As String, _
ByVal cBuf As String, _
ByVal iBufLen As Long) _
As Long


Sub Main()

Dim iNet_API_Status As Long
Dim cBuf As String
Dim cMsgName As String

cMsgName = StrConv("ANDREAS" + vbNullChar, vbUnicode)
cBuf = StrConv("Hello, world!" + vbNullChar, vbUnicode)

iNet_API_Status = NetSend(vbNullString, cMsgName, vbNullString, cBuf, 2 * Len(cBuf))
MsgBox (Str(iNet_API_Status))

End Sub


I also have a full list of the error codes that you can get, it is in a file called LMERR.H distributed with MSVC++ 4.0. Do you want it?

0
 

Author Comment

by:gmccull
ID: 1426141
Beauty! I knew I was missing some critical minor change. Good job!

Yes, I definitely would like to have that list of error codes! Thanks!
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1426142
OK, go to http://www.edu.linkoping.se/skolor/tornhagen/slask/lmerr.h

I will leave it there for a couple of days. Error codes with numerical values below 2100 can be found in the Win32 API reference.
0
 

Author Comment

by:gmccull
ID: 1426143
Got it. Thanks a million! You'll make me look like a genius!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 43
using Access 8 53
Saving history changes to sub form 4 26
bit defender blocks good applications 2 56
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now