0
我正在列表中的所有計算機上運行命令。我試圖找回一個文本文件,說每臺計算機通過或失敗。我正在使用下面的StreamWriter和函數進程。該進程正確運行,並且對數據文件和錯誤日誌都有權。然而,錯誤日誌總是說PASS的一切。重定向控制檯輸出以查找命令失敗的跡象
我無法在控制檯窗口中看到任何東西。我如何知道如何設置consoleOutput =「????」至?
Using swrr As New StreamWriter(ErrorLog, True)
For Each strUserName As String In strLines
Dim ConsoleOutput As String = GetCMDOutput(strUserName, saveFileDialog3.FileName & ".txt", exeSearch)
Console.ReadLine()
If ConsoleOutput = "blahblah" Then swrr.WriteLine("FAIL") Else swrr.WriteLine("PASS")
Next
End Using
Function GetCMDOutput(ByVal strUsername As String, ByVal strFileName As String, ByVal strExeSearch As String) As String
Dim Arg1 As String = strUsername
Dim Arg2 As String = strFileName
Dim Final As String = String.Format("/c pushd\\{0}\C$ && whoami.exe >> {1}", Arg1, Arg2)
Dim CMD As New Process
CMD.StartInfo.FileName = "cmd.exe"
CMD.StartInfo.Arguments = Final
CMD.StartInfo.UseShellExecute = False
CMD.StartInfo.RedirectStandardOutput = True
CMD.StartInfo.RedirectStandardInput = True
CMD.StartInfo.CreateNoWindow = True
CMD.Start()
Dim retval As String = CMD.StandardOutput.ReadToEnd
CMD.WaitForExit()
Return retval
End Function