'vb.net : how to get result from cmd to textbox

i trying to run this command in cmd and get the result to my textbox4.text without success command : cscript "%windir%\system32\slmgr.vbs" /xpr | findstr /S /M /I /C:"permanently"

result in need to get in my textbox4 : The machine is permanently activated.

i write this code without success :

    Dim qassam As String

    qassam = Shell("whoami")
    TextBox4.Text = CStr(qassam)

and also i found this but not working :

 Dim oProcess As New Process()
    Dim oStartInfo As New ProcessStartInfo("cmd.exe", "cscript %windir%\system32\slmgr.vbs /xpr | findstr /S /M /I /C:permanently ")
    oStartInfo.UseShellExecute = False
    oStartInfo.RedirectStandardOutput = True
    oProcess.StartInfo = oStartInfo
    oProcess.Start()

    Dim sOutput As String
    Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
        sOutput = oStreamReader.ReadToEnd()
    End Using

    TextBox4.Text = sOutput   'txtOutput being the output textbox.

im new at vb.net i need simple code please to understand



Solution 1:[1]

solved by just add this /k to ("cmd.exe", "/c cscript %windir%\system32\slmgr.vbs /xpr | findstr /S /M /I /C:permanently ")`

 Dim oProcess As New Process()
    Dim oStartInfo As New ProcessStartInfo("cmd.exe", " /c cscript ""%windir%\system32\slmgr.vbs"" /xpr | findstr ""The machine""")
    oStartInfo.UseShellExecute = False
    oStartInfo.RedirectStandardOutput = True
    oProcess.StartInfo = oStartInfo
    oProcess.Start()

    Dim sOutput As String
    Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
        sOutput = oStreamReader.ReadToEnd()
    End Using

    TextBox4.Text = sOutput

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Qassam Mahmoud