Click here to Skip to main content
15,791,934 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
start a cmd session in a windows form whit command "ipconfig"
but show an error on FnctionStartConsoleEvent
anyone help me?

What I have tried:

VB
Dim cdd() As String
    Event Avvia()
    Function FnctionStartConsoleEvent(e As KeyEventArgs) As EventHandler(Of ComboBox.ObjectCollection)
        If e.KeyData = Keys.Enter Then
            Dim process As Process = New Process
            With process
                '  .StartInfo.ErrorDialog = False
                .StartInfo.RedirectStandardInput = True
                .StartInfo.RedirectStandardOutput = True
                .StartInfo.UseShellExecute = False
                .StartInfo.FileName = "cmd.exe"
                .StartInfo.CreateNoWindow = True
                .StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            End With
            process.Start()
            Try
                process.StandardInput.WriteLine("cd/d " & cdd(3))
            Catch
            End Try
            process.StandardInput.WriteLine(ComboBox1.Text)
            process.StandardInput.WriteLine("echo [~cd~]%cd%[~cd~]")
            process.StandardInput.WriteLine("exit")
            Dim outpp As New TextBox
            outpp.Text = process.StandardOutput.ReadToEnd
            cdd = Split(outpp.Text, "[~cd~]")

            For i = 4 To outpp.Lines.Length - 6
                RichTextBox1.Text = RichTextBox1.Text & outpp.Lines(i).Substring(0) & vbCrLf
            Next
            ComboBox1.Items.Add(ComboBox1.Text)
            ComboBox1.Text = ""
            RichTextBox1.SelectionStart = RichTextBox1.Text.Length
            RichTextBox1.ScrollToCaret()
        End If
    End Function

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        AddHandler Avvia, AddressOf FnctionStartConsoleEvent
        If ComboBox1.SelectedText = "ipconfig" Then
            RaiseEvent Avvia()
        End If
    End Sub
Posted
Updated 31-Oct-16 8:58am
Comments
[no name] 30-Oct-16 10:40am    
Maybe. We can't read your mind though. We would have no idea which one out the possible 54365654745676 errors there are, which you chose to get.
Wendelius 30-Oct-16 11:25am    
Please post the exact error message you get and information on where it's thrown.
Member 12823823 30-Oct-16 14:03pm    
s22.postimg.org/ym6rsx5cx/ddd.jpg
Richard MacCutchan 31-Oct-16 4:17am    
That is not an error message.

1 solution

First problem:
You have an event which expects zero arguments.

You are trying to add a handler method which expects one argument - a KeyEventArgs instance.

Event handlers MUST match the signature of the event they handle. If they don't, you get the compiler error shown in your screen-shot.



Second problem:
You have declared that FnctionStartConsoleEvent returns an event handler method which will accept two arguments - sender As Object and args As ComboBox.ObjectCollection.

The method does no such thing.

Since the method doesn't return anything, VB "helpfully" inserts a Return Nothing before the function exits. If you try to use the return value, you will get a NullReferenceException.



You need to start again, and read a few tutorials on how events work.

Events (Visual Basic)[^]
Raising Events and Responding to Events[^]
Walkthrough: Declaring and Raising Events (Visual Basic)[^]
Step by Step: Event handling in VB.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900