1

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?

nejjm
  • 11
  • 1
  • `Process.Start` does not wait until the process completes. To do that use the `WaitForExit` method on the Process object (either the [parameter-less method](http://msdn.microsoft.com/en-us/library/fb4aw7b8(v=vs.110).aspx) or the [overload specifying a timeout](http://msdn.microsoft.com/en-us/library/ty0d8k56(v=vs.110).aspx)). – Robert Westerlund Jul 20 '14 at 09:45
  • Also, since you are redirecting both standard output and standard error, be advised that there is a potential deadlock issue. Read the docs for the RedirectStandardError property for details. – Chris Dunaway Jul 21 '14 at 15:01

0 Answers0