2017-03-14 4 views
1

cmdでこのコマンドを実行し、結果をtextbox4.textに取得しようとしました。 コマンド:cscript "%windir%\ system32 \ slmgr.vbs"/xpr | findstr/S/M/I/C: "永久に"vb.net:cmdから結果をテキストボックスに取得する方法

私のtextbox4に入る必要があります。 マシンは永久に起動します。

私は成功せずにこのコードを書く:

Dim qassam As String 

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

をしても、私はこれを見つけたが、動作していない:

vb.netで
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. 

イム新しい私は、単純なコードが必要

+0

デバッグを試しましたか?どのようなエラーがありますか? –

+0

私は何のエラーもありません空白のテキストボックスがあります –

+0

あなたはデバッグを調べる必要があります - あなたのコードにブレークポイントを置き、各ポイントで出力を確認してください。そうすれば、正確に何が動作していないのかを知ることができます(ストリーム、プロセスなのでしょうか?)。 –

答えて

0
を理解してください

を に追加するか、「/ c cscript%windir%\ system32 \ slmgr.vbs/xpr | findstr/S/M/I/C:永続的に」)

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 
関連する問題