【问题标题】:vb.net : how to get result from cmd to textboxvb.net:如何从 cmd 获取结果到文本框
【发布时间】:2017-08-04 13:54:32
【问题描述】:

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

结果需要进入我的 textbox4 : 机器被永久激活。

我写这段代码没有成功:

    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 的新手,我需要简单的代码,请理解

【问题讨论】:

  • 你试过调试吗?您遇到了什么错误(如果有)?
  • 我没有错误我有一个空白文本框
  • 您需要查看调试 - 在代码上放置断点并检查每个点的输出。这样你就可以找出到底是什么不工作(是流还是过程?)。

标签: vb.net shell cmd textbox command


【解决方案1】:

只需将此 /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

【讨论】:

  • 我一定是失明了,大声笑...我没有看到您在解决方案中添加 /k 的位置? ;)
猜你喜欢
  • 2014-03-25
  • 1970-01-01
  • 2017-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-15
相关资源
最近更新 更多