在案例陈述

时间:2017-03-26 09:18:36

标签: vb.net windows shell cmd case

我试图通过运行此代码来获取cmd的Windows许可证状态

    Dim oProcess As New Process()
    Dim oStartInfo As New ProcessStartInfo("cmd.exe", " /c cscript ""%windir%\system32\slmgr.vbs"" /xpr | findstr ""The machine""")
    oStartInfo.CreateNoWindow = True
    oStartInfo.WindowStyle = ProcessWindowStyle.Hidden


    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

    Select Case sOutput
        Case Is = "The machine is permanently activated."
            TextBox4.Text = "activated"



    End Select

代码工作正常,但我的textbox4上显示的结果是:机器被永久激活。我需要把这个结果带到案例陈述

Select Case sOutput
        Case Is = "The machine is permanently activated."
            TextBox4.Text = "activated"

如果我得到我需要的全部机器被永久激活。来自cmd的状态然后显示在textbox4字(激活)

1 个答案:

答案 0 :(得分:0)

可能是输出在末尾包含空格或换行符。在字符串上调用Trim()以删除任何前导或尾随空格和/或换行符。

Select Case sOutput.Trim()