I have a fairly straight-forward process where I call a powershell window with a few arguments that are used to test replication for Active Directory. As you can see below I hide this window and redirect the output of the results into the resultsStorage variable:
Try
Dim sCommand As String = "powershell.exe"
sArgs = "dcdiag /test:replications; repadmin /showrepl; repadmin /replsummary /errorsonly /sort:failures"
Dim psi As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo(sCommand, sArgs)
psi.UseShellExecute = False
psi.CreateNoWindow = True
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
Dim proc As System.Diagnostics.Process = System.Diagnostics.Process.Start(psi)
Dim errorResults As String = proc.StandardError.ReadToEnd
If errorResults <> "" Then
resultsStorage = errorResults
Else
resultsStorage = proc.StandardOutput.ReadToEnd
End If
Catch ex As Exception
resultsStorage = "An error was encountered running replication test(s):" & vbNewLine & ex.ToString
End Try
This is working quite well in most circumstances. However, in some cases replication testing with the above arguments can take a lengthy amount of time. (10+ minutes) I've noticed in these circumstances that nothing will ever be returned. Ruling out this specific argument, I've tried several different arguments and I've noticed that pretty much any argument that takes any real length of time will never return a value. Is there a limitation on the amount of time the process.start will wait? Any suggestions on how to improve this?