好的,我在尝试执行循环时遇到了问题我有一个包含服务器列表的变量,当我尝试循环时它只循环一次并停止
我在下面有部分代码可以尝试让您了解我在做什么,尽管我已经删除了任何可以指向我工作的公司的数据。
代码的第一部分,从域中获取服务器列表
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 的第一行被使用,没有其他行被循环,所以基本上只有调试的输出。写(“线是:”&线)是
Line is : SERVERxafe01
所以我从来没有让它通过其他服务器循环>
我只是编写代码以尝试使我的工作更有效率,但是我不认为自己是程序员,因为我很容易感到沮丧并且在专注于代码的同时接听电话会有点前卫
所以欢迎任何想法,谢谢。