vb.net : 如何从 cmd 获取结果到文本框

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

我试图 运行 在 cmd 中执行此命令并将结果发送到我的 textbox4.text 但没有成功 命令:cscript "%windir%\system32\slmgr.vbs" /xpr | findstr /S /M /I /C:"permanently"

结果需要进入我的文本框4: 机器永久激活。

我写这段代码没有成功:

    Dim qassam As String

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

我也发现了这个但没有用:

 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.

我是 vb.net 的新人,我需要简单的代码,请理解

只需将 /k 添加到即可解决 ("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