わかりました、ループを実行しようとして問題が発生しました。サーバーのリストを含む変数があり、ループしようとすると、ループが 1 回だけ停止します。
以下にコードの一部を示します。これは、私が何をしているのかを理解してもらうためのものですが、私が働いている会社を示すデータはすべて削除しています。
コードの最初の部分で、ドメインからサーバーのリストを取得します
Dim oStartInfo As New ProcessStartInfo("c:\windows\system32\dsquery.exe", "computer " & cnameodd & oservpath & " -o rdn")
oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oStartInfo.RedirectStandardError = True
oStartInfo.CreateNoWindow = True
oProcess.StartInfo = oStartInfo
oProcess.Start()
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
sOutput = oStreamReader.ReadToEnd()
sOutPut の出力は次のようになります (debug.write("servers: " & sOutPut) を介して以下のコードに示されています)
"SERVERxafe01"
"SERVERxafe02"
"SERVERxafe03"
"SERVERxafe04"
"SERVERxafe05"
"SERVERxafe06"
次に、各サーバーのコマンドをループする出力を取得しようとしています
If sOutput = "" Then
Debug.Write("No Servers Found")
Else
Debug.Write("Servers: " & sOutput)
Dim reader As New StringReader(sOutput.Replace(Chr(34), ""))
While True
Dim line = reader.ReadLine()
Debug.Write("Line is" & line)
If line IsNot Nothing Then
Dim command As String = " user " & user & " /server:" & line
Dim pStartInfo As New ProcessStartInfo("c:\windows\sysnative\query.exe", command)
pStartInfo.UseShellExecute = False
pStartInfo.RedirectStandardOutput = True
pStartInfo.RedirectStandardError = True
pStartInfo.CreateNoWindow = True
pProcess.StartInfo = pStartInfo
pProcess.Start()
Using pStreamReader As System.IO.StreamReader = pProcess.StandardError
sOutput = pStreamReader.ReadToEnd()
Debug.Write(sOutput & "Error " & command)
End Using
Using pStreamReader As System.IO.StreamReader = pProcess.StandardOutput
sOutput = pStreamReader.ReadToEnd()
Debug.Write(sOutput & "Output" & command)
Return sOutput
End Using
End If
End While
End If
End Using
コードでは、debug.write を実行して現在処理している行を出力しようとしていますが、これを実行するたびに、使用されている sOutPut の最初の行のみが表示され、他の行がループされていないため、基本的にデバッグの出力のみが表示されます。 write("Line is :" & line) は
Line is : SERVERxafe01
そのため、他のサーバーを介してループすることはありません>
私は自分の仕事をもう少し生産的にしようとコードを書いているだけですが、イライラしやすく、コードに集中しているときに電話をかけると少しエッジが効くので、自分自身をプログラマーだとは考えていません
どんなアイデアでも大歓迎です、ありがとう。