Net Send

G

Guest

How do I send a message using Net Send to a group of computers using VB.Net? I would like to provide our I.T. guy with a small app that he can use to select computers from a list of active computers and send them a popup message, like the way Net Send does. Which classes would I use to: loop through the available computers on our network and send a Net Send message. If Net Send is not an option in VB.Net, what other method would you recommend

Thank you in advance
Richar
 
W

William Ryan eMVP

If you have Win 2000 or later (active directory) you can query active
directory like this...
http://www.knowdotnet.com/articles/directoryservices.html

Then use Process.Start passing in Net Send, the computer name and the
message.
Richard said:
How do I send a message using Net Send to a group of computers using
VB.Net? I would like to provide our I.T. guy with a small app that he can
use to select computers from a list of active computers and send them a
popup message, like the way Net Send does. Which classes would I use to:
loop through the available computers on our network and send a Net Send
message. If Net Send is not an option in VB.Net, what other method would you
recommend?
 
G

Guest

Thank you! I was able to loop through our computers with the code from that web page. However, I'm getting a "file doesn't exist" when I try to access Net Send through a process. Here is the code I'm using:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim myProcess As New Process
'ListBox1 is filled with computer names.
myProcess.Start("Net Send", ListBox1.SelectedItem & " Did you get this?")
myProcess.CloseMainWindow()
myProcess.Close()

End Sub

Thanks again, Richard

----- William Ryan eMVP wrote: -----

If you have Win 2000 or later (active directory) you can query active
directory like this...
http://www.knowdotnet.com/articles/directoryservices.html

Then use Process.Start passing in Net Send, the computer name and the
message.
Richard said:
How do I send a message using Net Send to a group of computers using
VB.Net? I would like to provide our I.T. guy with a small app that he can
use to select computers from a list of active computers and send them a
popup message, like the way Net Send does. Which classes would I use to:
loop through the available computers on our network and send a Net Send
message. If Net Send is not an option in VB.Net, what other method would you
recommend?
 
A

Ayaz Ahmed

Hello,


'API Declarations

Option Explicit

Private Declare Function NetMessageBufferSend Lib "netapi32.dll" _
(ByVal servername As String, _
ByVal msgname As String, _
ByVal fromname As String, _
ByVal Buffer As String, _
ByVal BufSize As Long) As Long

Private Const NERR_SUCCESS As Long = 0
Private Const NERR_BASE As Long = 2100
Private Const NERR_NetworkError As Long = (NERR_BASE + 36)
Private Const NERR_NameNotFound As Long = (NERR_BASE + 173)
Private Const NERR_UseNotFound As Long = (NERR_BASE + 150)
Private Const ERROR_ACCESS_DENIED As Long = 5
Private Const ERROR_BAD_NETPATH As Long = 53
Private Const ERROR_NOT_SUPPORTED As Long = 50
Private Const ERROR_INVALID_PARAMETER As Long = 87
Private Const ERROR_INVALID_NAME As Long = 123
Public Function NetSendMessage(ByVal sSendTo As String, ByVal sMessage
As String) As Long
Dim ret As Long
sSendTo = StrConv(sSendTo, vbUnicode)
sMessage = StrConv(sMessage, vbUnicode)
NetSendMessage = NetMessageBufferSend(vbNullString, sSendTo,
vbNullString, _
sMessage, Len(sMessage))
End Function

Public Function NetSendErrorMessage(ErrNum As Long) As String
Select Case ErrNum
Case NERR_SUCCESS
'NetSendErrorMessage = "The message was successfully sent"
Case NERR_NameNotFound
NetSendErrorMessage = "Send To not found"
Case NERR_NetworkError
NetSendErrorMessage = "General network error occurred"
Case NERR_UseNotFound
NetSendErrorMessage = "Network connection not found"
Case ERROR_ACCESS_DENIED
NetSendErrorMessage = "Access to computer denied"
Case ERROR_BAD_NETPATH
NetSendErrorMessage = "Sent From server name not found."
Case ERROR_INVALID_PARAMETER
NetSendErrorMessage = "Invalid parameter(s) specified."
Case ERROR_NOT_SUPPORTED
NetSendErrorMessage = "Network request not supported."
Case ERROR_INVALID_NAME
NetSendErrorMessage = "Illegal character or malformed name."
Case Else
NetSendErrorMessage = "Unknown error executing command."
End Select
End Function
Private Sub Command2_Click()
Dim ret As Long

If Text1.Text = "" Then
MsgBox "Please Specify Computer Name", vbCritical, "Alert"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "Please Specify Sending Message", vbCritical, "Alert"
Text2.SetFocus
Exit Sub
End If

ret = NetSendMessage(Text1.Text, Text2.Text)
If ret <> 0 Then
MsgBox NetSendErrorMessage(ret), vbCritical, "Error"
Else
' MsgBox NetSendErrorMessage(ret), vbInformation, "NetSend"
MsgBox "Message Succesfully Send", vbInformation, "NetSend"
End If
End Sub


Thanks,



Warm Regards,

Ayaz Ahmed
Software Engineer & Web Developer
Creative Chaos (Pvt.) Ltd.
"Managing Your Digital Risk"
http://www.csquareonline.com
Karachi, Pakistan
Mobile +92 300 2280950
Office +92 21 455 2414
 
G

Guest

I really appreciate your reply and code, and will try to convert it to use with VB.Net

Thank you, Richar

----- Ayaz Ahmed wrote: ----

Hello


'API Declaration

Option Explici

Private Declare Function NetMessageBufferSend Lib "netapi32.dll"
(ByVal servername As String,
ByVal msgname As String,
ByVal fromname As String,
ByVal Buffer As String,
ByVal BufSize As Long) As Lon

Private Const NERR_SUCCESS As Long =
Private Const NERR_BASE As Long = 210
Private Const NERR_NetworkError As Long = (NERR_BASE + 36
Private Const NERR_NameNotFound As Long = (NERR_BASE + 173
Private Const NERR_UseNotFound As Long = (NERR_BASE + 150
Private Const ERROR_ACCESS_DENIED As Long =
Private Const ERROR_BAD_NETPATH As Long = 5
Private Const ERROR_NOT_SUPPORTED As Long = 5
Private Const ERROR_INVALID_PARAMETER As Long = 8
Private Const ERROR_INVALID_NAME As Long = 12
Public Function NetSendMessage(ByVal sSendTo As String, ByVal sMessag
As String) As Lon
Dim ret As Lon
sSendTo = StrConv(sSendTo, vbUnicode
sMessage = StrConv(sMessage, vbUnicode
NetSendMessage = NetMessageBufferSend(vbNullString, sSendTo
vbNullString,
sMessage, Len(sMessage)
End Functio

Public Function NetSendErrorMessage(ErrNum As Long) As Strin
Select Case ErrNu
Case NERR_SUCCES
'NetSendErrorMessage = "The message was successfully sent
Case NERR_NameNotFoun
NetSendErrorMessage = "Send To not found
Case NERR_NetworkErro
NetSendErrorMessage = "General network error occurred
Case NERR_UseNotFoun
NetSendErrorMessage = "Network connection not found
Case ERROR_ACCESS_DENIE
NetSendErrorMessage = "Access to computer denied
Case ERROR_BAD_NETPAT
NetSendErrorMessage = "Sent From server name not found.
Case ERROR_INVALID_PARAMETE
NetSendErrorMessage = "Invalid parameter(s) specified.
Case ERROR_NOT_SUPPORTE
NetSendErrorMessage = "Network request not supported.
Case ERROR_INVALID_NAM
NetSendErrorMessage = "Illegal character or malformed name.
Case Els
NetSendErrorMessage = "Unknown error executing command.
End Selec
End Functio
Private Sub Command2_Click(
Dim ret As Lon

If Text1.Text = "" The
MsgBox "Please Specify Computer Name", vbCritical, "Alert
Text1.SetFocu
Exit Su
End I
If Text2.Text = "" The
MsgBox "Please Specify Sending Message", vbCritical, "Alert
Text2.SetFocu
Exit Su
End I

ret = NetSendMessage(Text1.Text, Text2.Text
If ret <> 0 The
MsgBox NetSendErrorMessage(ret), vbCritical, "Error
Els
' MsgBox NetSendErrorMessage(ret), vbInformation, "NetSend
MsgBox "Message Succesfully Send", vbInformation, "NetSend
End I
End Su


Thanks



Warm Regards

Ayaz Ahmed
Software Engineer & Web Develope
Creative Chaos (Pvt.) Ltd
"Managing Your Digital Risk
http://www.csquareonline.co
Karachi, Pakista
Mobile +92 300 2280950
Office +92 21 455 241

*** Sent via Developersdex http://www.developersdex.com **
Don't just participate in USENET...get rewarded for it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top