Net Send command in vb.net

Dear Experts,
Please tell me how i write net send command in vb.net language..
virafhAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

habeeballahCommented:
What do you mean?. You want to use the "net send" command in VB or make your own net-send?
0
virafhAuthor Commented:
yes i want to use the "net send" command in VB
0
Bob LearnedCommented:
You can use the System.Diagnostics.Process class to execute the external NET SEND command:


Imports System
Imports System.Diagnostics

Public Class NetSend

  ''' -----------------------------------------------------------------------------
  ''' <summary>
  ''' Send a message to a user or a domain
  ''' </summary>
  ''' <remarks>
  '''	  The syntax of this command is:
  '''     NET SEND
  ''' {name | * | /DOMAIN[:name] | /USERS} message
  ''' </remarks>
  ''' <history>
  ''' 	[Bob]	6/7/2006	Created
  ''' </history>
  ''' -----------------------------------------------------------------------------
  Public Shared Sub SendMessage(ByVal name As String, ByVal domain As String, ByVal message As String)

    Dim process As New Process()

    Dim arguments As String = "SEND"

    If domain.Length > 0 Then
      arguments &= " /DOMAIN:" & domain
    End If

    process.StartInfo.FileName = "net.exe"
    process.StartInfo.Arguments = arguments

    process.StartInfo.CreateNoWindow = True
    process.StartInfo.ErrorDialog = False
    process.StartInfo.RedirectStandardOutput = False
    process.StartInfo.RedirectStandardInput = False
    process.StartInfo.RedirectStandardError = False
    process.StartInfo.UseShellExecute = False

    process.Start()

    process.WaitForExit(2000)

  End Sub

End Class

Open in new window

0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Shahan AyyubSenior Software EngineerCommented:
0
habeeballahCommented:
TheLearnedOne has forgotten to add message in the arguments (line 26). So it has to be

arguments &= " /DOMAIN:" & domain & " " & message
0
virafhAuthor Commented:
Dear TheLearnedOne,
Where i can gove my IP Address in your code and please tell me what is net.exe
0
habeeballahCommented:
from the command prompt type "net" and press enter to see what it is. By the way you want to use "net send" from your VB program, then how come you don't know what is net.exe. It is this exe you are going to use by sending the various parameters through your code.

The actual syntax of net send is as follows:

net send 10.0.0.68 "hello this is a message"

or

net send habcomp "hello this is a message"

Now it is your responsibility to adjust the code in order to put the arguments for net command.
0
Bob LearnedCommented:
"forgotten to add message"
Good catch!!  That untested code was from my bag-o-tricks.  That'll teach me to post without testing (d'oh).
0
virafhAuthor Commented:
please check my below code.shell command not working but when i am writing shell command
int this way shell("192.168.0.111") its working
where i am doing wrong please tell me
 Dim domain As String
        Dim message As String
        Dim cmd As String = "net send"
        message = "heloooooooo"
        domain = "192.168.0.11"
        Dim address As IPAddress = IPAddress.Parse("192.168.0.11")
        If Not address Is Nothing Then
            Dim ping As Ping = New Ping()
            Dim reply As PingReply = ping.Send(address, 1000)
            If reply.Status = IPStatus.Success Then
                Shell(cmd & domain & message)
            End If
        End If

Open in new window

0
Bob LearnedCommented:
You don't have spaces between the arguments, so everything is running together.
0
virafhAuthor Commented:
can you post example please
0
Bob LearnedCommented:
I mean put spaces in between the parts:

Shell(cmd & " " & domain & " " & message)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.