none
Using DOS commands in VS 2013:Another odd ball project for the books RRS feed

  • Question

  • Hello all!

    It’s been awhile and I’m back with another odd ball application.

    I’ve never played much with Visual Studio 2013 and DOS. I’m starting with a plane-Jane form, nothing special.

    I have a need to create an application that will use DOS. I know, DOS! Yes. It’s still used very widely.

    What I need to do is:

    1.)    1.)Have text box where I can enter a server IP

    2.)    2.)Have a text box where I can enter a time in minutes. This Text box will be controlling a Timer function.

    3.)  3.)  Have a check box that will enable the timer

    4.)   4.) Have a start button that will start the timer (based on the contents in the text box for time)

    5.)   5.) A stop button to Stop the Timer cycle

    6.)     6.)And finally a TEST button

    What does this all do? Pings a server of the IP I entered into text box 1.

    I’m working with a remote router that likes to fall asleep. Boss wants me to come up with a way we can enter the router’s IP addy, select a time in minutes and “Ping” this thing ever so many minutes.

    I’ve included the form layout and am not sure exactly where to start. I’d like a text box to display the results of the ping when I click the test button as well.

    So, I guess the first task is:

    How can one enter an IP addy into a text box and tell DOS to Ping that IP addy and display that result in a text box?

    Please let me know if this is not the right forum, it’s been a few years since I’ve been on here. Any help will be greatly appreciated.

    Thanks in advance, these forums have helped me in some very odd ball projects in the past. I’d like to work through the entire project on here in this thread. Things discovered in this project could really be helpful to others.

    Thanks,

    -Chris

    Tuesday, February 4, 2014 2:14 AM

Answers

  • You have to use the Application.Process class. 

    I don't know what program language you use, if it is VB then look at these samples on our website. There is of course much more.

    http://www.vb-tips.com/StartProcess.aspx

    Take by the way for this kind of question your program forum that is for VB

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral


    Success
    Cor


    • Edited by Cor Ligthert Wednesday, February 5, 2014 9:48 AM
    • Marked as answer by Marvin_Guo Tuesday, February 11, 2014 11:14 AM
    Wednesday, February 5, 2014 9:47 AM
  • Hi,

    >>How can one enter an IP addy into a text box and tell DOS to Ping that IP addy and display that result in a text box?

    You could create CMD process and use the redirected input/output of a process, then disply the result into textbox.Here is a sample code and screenshot for you reference:

    private void button2_Click(object sender, EventArgs e)
            {
                RunCommand("Ping " +textBox2.Text );
            }
            private void RunCommand(string command)
            {
                var process = new Process()
                {
                    StartInfo = new ProcessStartInfo("cmd")
                    {
                        UseShellExecute = false,
                        RedirectStandardInput = true,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true,
                        Arguments = String.Format("/c \"{0}\"", command),
                    }
                };
                process.OutputDataReceived += OutputHandler;
                process.Start();
                process.BeginOutputReadLine();
                
                process.WaitForExit();
            }
    
            private void OutputHandler(object sendingProcess, DataReceivedEventArgs e)
            {
                if (textBox1.InvokeRequired) { textBox1.BeginInvoke(new DataReceivedEventHandler(OutputHandler), new[] { sendingProcess, e }); }
                else
                {
                    textBox1.AppendText(e.Data ?? string.Empty);
                    textBox1.AppendText("\r\n");
                }
            }

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Marvin_Guo Tuesday, February 11, 2014 11:14 AM
    Wednesday, February 5, 2014 10:50 AM
  • Hi,

    Try to use the following code using VB.NET,It works fine in my side:

    Imports System.Net.NetworkInformation
    Imports System.Threading
    Imports System.Threading.Tasks
    Imports System.Diagnostics
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            RunCommand("Ping " + TextBox2.Text)
        End Sub
        Private Sub RunCommand(command As String)
            Dim process = New Process()
            process.StartInfo = New ProcessStartInfo("cmd") With { _
                 .UseShellExecute = False, _
                 .RedirectStandardInput = True, _
                 .RedirectStandardOutput = True, _
                 .CreateNoWindow = True, _
                 .Arguments = [String].Format("/c ""{0}""", command)
             }
            AddHandler Process.OutputDataReceived, AddressOf OutputHandler
            Process.Start()
            Process.BeginOutputReadLine()
    
            Process.WaitForExit()
        End Sub
    
        Private Sub OutputHandler(sendingProcess As Object, e As DataReceivedEventArgs)
            If TextBox1.InvokeRequired Then
                TextBox1.BeginInvoke(New DataReceivedEventHandler(AddressOf OutputHandler), New Object() {sendingProcess, e})
            Else
                TextBox1.AppendText(If(e.Data, String.Empty))
                TextBox1.AppendText(vbCr & vbLf)
            End If
        End Sub
    
    End Class

    Notice: you should add the two textbox control and a button in your windows form application.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Marvin_Guo Thursday, February 6, 2014 2:06 AM
    • Marked as answer by Marvin_Guo Tuesday, February 11, 2014 11:14 AM
    Thursday, February 6, 2014 2:06 AM

All replies

  • Grrrr.... I have a screen shot of my form, but can't get it uploaded. Hopefuly tomorrow MS will let me upload my screen shot.

    Tuesday, February 4, 2014 2:16 AM
  • I found my old acount. Here's the form I created. Hope it helps clear up any answers.


    Dr.Bones- " If my application is too hard for a 5th grader to run, I've made too complicated"

    Tuesday, February 4, 2014 2:45 AM
  • Hi,

    I am moving your issue to the Winform forum so that you can get better support.

    Thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 5, 2014 5:20 AM
  • You have to use the Application.Process class. 

    I don't know what program language you use, if it is VB then look at these samples on our website. There is of course much more.

    http://www.vb-tips.com/StartProcess.aspx

    Take by the way for this kind of question your program forum that is for VB

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral


    Success
    Cor


    • Edited by Cor Ligthert Wednesday, February 5, 2014 9:48 AM
    • Marked as answer by Marvin_Guo Tuesday, February 11, 2014 11:14 AM
    Wednesday, February 5, 2014 9:47 AM
  • Hi,

    >>How can one enter an IP addy into a text box and tell DOS to Ping that IP addy and display that result in a text box?

    You could create CMD process and use the redirected input/output of a process, then disply the result into textbox.Here is a sample code and screenshot for you reference:

    private void button2_Click(object sender, EventArgs e)
            {
                RunCommand("Ping " +textBox2.Text );
            }
            private void RunCommand(string command)
            {
                var process = new Process()
                {
                    StartInfo = new ProcessStartInfo("cmd")
                    {
                        UseShellExecute = false,
                        RedirectStandardInput = true,
                        RedirectStandardOutput = true,
                        CreateNoWindow = true,
                        Arguments = String.Format("/c \"{0}\"", command),
                    }
                };
                process.OutputDataReceived += OutputHandler;
                process.Start();
                process.BeginOutputReadLine();
                
                process.WaitForExit();
            }
    
            private void OutputHandler(object sendingProcess, DataReceivedEventArgs e)
            {
                if (textBox1.InvokeRequired) { textBox1.BeginInvoke(new DataReceivedEventHandler(OutputHandler), new[] { sendingProcess, e }); }
                else
                {
                    textBox1.AppendText(e.Data ?? string.Empty);
                    textBox1.AppendText("\r\n");
                }
            }

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Marvin_Guo Tuesday, February 11, 2014 11:14 AM
    Wednesday, February 5, 2014 10:50 AM
  • Sorry for the question. this looks PERFECT! But is this in Visual Basic? I'm not sure where the code needs to go in my project. I'm in Visual Studio 2013 and using a plain windows form VB. Let me play around with this a bit...

    Thank you so much!!

    Wednesday, February 5, 2014 1:54 PM
  • Here's the code so far with nothing but ref. Where does the code you provided go? I get all kinds of issues with the above code.

    Thank you again for all your help :)

    Public

    ClassForm1


      

       

    PrivateSubForm1_Load(sender AsObject, e AsEventArgs) HandlesMyBase.Load

       

    EndSub


       

    PrivateSubTextBox2_TextChanged(sender AsObject, e AsEventArgs) HandlesTextBox2.TextChanged

       

    EndSub


       

    PrivateSubTextBox1_TextChanged(sender AsObject, e AsEventArgs) HandlesTextBox1.TextChanged

       

    EndSub


       

    PrivateSubButton1_Click(sender AsObject, e AsEventArgs) HandlesButton1.Click

       

    EndSub

    End

    Class

    Wednesday, February 5, 2014 2:02 PM
  • Finally figured this out. the code you provided is in C and I'm creating this in Visual Basic. This looks like EXACTLY what I'm looking for, how would one get this accomplished in a Visual Basic form ?
    Wednesday, February 5, 2014 2:12 PM
  • tried to convert this to VB wih no luck. Still chugging away
    Wednesday, February 5, 2014 5:43 PM
  • Hi,

    Try to use the following code using VB.NET,It works fine in my side:

    Imports System.Net.NetworkInformation
    Imports System.Threading
    Imports System.Threading.Tasks
    Imports System.Diagnostics
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            RunCommand("Ping " + TextBox2.Text)
        End Sub
        Private Sub RunCommand(command As String)
            Dim process = New Process()
            process.StartInfo = New ProcessStartInfo("cmd") With { _
                 .UseShellExecute = False, _
                 .RedirectStandardInput = True, _
                 .RedirectStandardOutput = True, _
                 .CreateNoWindow = True, _
                 .Arguments = [String].Format("/c ""{0}""", command)
             }
            AddHandler Process.OutputDataReceived, AddressOf OutputHandler
            Process.Start()
            Process.BeginOutputReadLine()
    
            Process.WaitForExit()
        End Sub
    
        Private Sub OutputHandler(sendingProcess As Object, e As DataReceivedEventArgs)
            If TextBox1.InvokeRequired Then
                TextBox1.BeginInvoke(New DataReceivedEventHandler(AddressOf OutputHandler), New Object() {sendingProcess, e})
            Else
                TextBox1.AppendText(If(e.Data, String.Empty))
                TextBox1.AppendText(vbCr & vbLf)
            End If
        End Sub
    
    End Class

    Notice: you should add the two textbox control and a button in your windows form application.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Marvin_Guo Thursday, February 6, 2014 2:06 AM
    • Marked as answer by Marvin_Guo Tuesday, February 11, 2014 11:14 AM
    Thursday, February 6, 2014 2:06 AM