J
Jared
Hello all,
I'm having problems with the NetMessageBufferSend call. First, I'll
explain what is happening and then I will post some code. I have written a
net send interface a while back and everything was working fine, recently I
noticed a lot of failures when I try to send a message.
I've also noticed that most of the "problem" computers are running Windows
XP.
I receive error message 2273 (NERR_NameNotFound); this is funny to be
because the output of "net name" shows my computer name as being in the
local name table.
To fix this I tried calling the NetMessageNameAdd function, but, I receive
2276 (NERR_AlreadyExists). I checked the dependencies of the Messenger
service, and made sure everything was started.
I can recreate the problem on my home computer (XP Pro), I also have a
virtual server on my pc (2000 AS) in which the program works fine. I've
spent the entire day trying to find an answer for this and I came up with
nothing. I even registered the Win2000 version of netapi32.dll on my
computer using a different name with the exact same results. I can however
bring up a command window and net send my self without a problem. I am not
having very much luck here!
A second question, how do you send a message to a specific user account
using vb.net? I haven't been able to find this answer either. Any help would
be greatly appreciated.
TIA,
Jared
Here are the calls:
Private Structure NetMessageData
Dim sServerName As String
Dim sSendTo As String
Dim sSendFrom As String
Dim sMessage As String
End Structure
'START HERE
Public Function SendMessageToComputer() As Boolean
Dim sMessage As String = Space$(MESSAGE_SIZE * 2) 'MESSAGE_SIZE = 1024
sMessage = Me.Message
Dim success As Long
Dim SingleMessage As New NetMessageData
With SingleMessage
.sMessage = Me.Message
.sSendFrom = Me.SendFrom
.sSendTo = Me.SendTo
If Not .sServerName = Nothing Then .sServerName = Me.Server
End With
success = Me.NetSendMessage(SingleMessage)
Select Case success
Case ERROR_ACCESS_DENIED
Return False
Case ERROR_BAD_NETPATH
Return False
Case ERROR_INVALID_PARAMETER
Return False
Case ERROR_NOT_SUPPORTED
Return False
Case ERROR_INVALID_NAME
Return False
Case NERR_BASE
Return False
Case NERR_SUCCESS
Return True
Case NERR_NETWORK_ERROR
Return False
Case NERR_NAME_NOT_FOUND
Return False
Case NERR_USE_NOT_FOUND
Return False
End Select
End Function
Private Function NetSendMessage(ByVal msgData As NetMessageData) As Long
Dim sMessage As String
Dim success As Long
With msgData
If Len(.sMessage) > 0 And Len(.sSendTo) > 0 Then
sMessage = Space$(MESSAGE_SIZE * 2)
sMessage = .sMessage & sMessage
success = Win32.NetMessageBufferSend(.sServerName, .sSendTo,
..sSendFrom, sMessage, MESSAGE_SIZE * 2)
End If
End With
Return success
End Function
Friend 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 Int32) As Int32
End Function
'Other DllImports...
End Class
I'm having problems with the NetMessageBufferSend call. First, I'll
explain what is happening and then I will post some code. I have written a
net send interface a while back and everything was working fine, recently I
noticed a lot of failures when I try to send a message.
I've also noticed that most of the "problem" computers are running Windows
XP.
I receive error message 2273 (NERR_NameNotFound); this is funny to be
because the output of "net name" shows my computer name as being in the
local name table.
To fix this I tried calling the NetMessageNameAdd function, but, I receive
2276 (NERR_AlreadyExists). I checked the dependencies of the Messenger
service, and made sure everything was started.
I can recreate the problem on my home computer (XP Pro), I also have a
virtual server on my pc (2000 AS) in which the program works fine. I've
spent the entire day trying to find an answer for this and I came up with
nothing. I even registered the Win2000 version of netapi32.dll on my
computer using a different name with the exact same results. I can however
bring up a command window and net send my self without a problem. I am not
having very much luck here!
A second question, how do you send a message to a specific user account
using vb.net? I haven't been able to find this answer either. Any help would
be greatly appreciated.
TIA,
Jared
Here are the calls:
Private Structure NetMessageData
Dim sServerName As String
Dim sSendTo As String
Dim sSendFrom As String
Dim sMessage As String
End Structure
'START HERE
Public Function SendMessageToComputer() As Boolean
Dim sMessage As String = Space$(MESSAGE_SIZE * 2) 'MESSAGE_SIZE = 1024
sMessage = Me.Message
Dim success As Long
Dim SingleMessage As New NetMessageData
With SingleMessage
.sMessage = Me.Message
.sSendFrom = Me.SendFrom
.sSendTo = Me.SendTo
If Not .sServerName = Nothing Then .sServerName = Me.Server
End With
success = Me.NetSendMessage(SingleMessage)
Select Case success
Case ERROR_ACCESS_DENIED
Return False
Case ERROR_BAD_NETPATH
Return False
Case ERROR_INVALID_PARAMETER
Return False
Case ERROR_NOT_SUPPORTED
Return False
Case ERROR_INVALID_NAME
Return False
Case NERR_BASE
Return False
Case NERR_SUCCESS
Return True
Case NERR_NETWORK_ERROR
Return False
Case NERR_NAME_NOT_FOUND
Return False
Case NERR_USE_NOT_FOUND
Return False
End Select
End Function
Private Function NetSendMessage(ByVal msgData As NetMessageData) As Long
Dim sMessage As String
Dim success As Long
With msgData
If Len(.sMessage) > 0 And Len(.sSendTo) > 0 Then
sMessage = Space$(MESSAGE_SIZE * 2)
sMessage = .sMessage & sMessage
success = Win32.NetMessageBufferSend(.sServerName, .sSendTo,
..sSendFrom, sMessage, MESSAGE_SIZE * 2)
End If
End With
Return success
End Function
Friend 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 Int32) As Int32
End Function
'Other DllImports...
End Class