Sam Saarian
Sam Saarian

Reputation: 1146

WaitForExit won't wait if exe is in DVD rom

'WaitForExit' won't wait if executable is running from DVD ROM, however it "waits" if run from C: drive or an external flash drive. Any clue why this property doesn't work?

  1. I see this process on task manager
  2. I'm using VB.NET 2010.

This is the code I have.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

    Try
        Dim p As New Process
        With p
            With p.StartInfo
                .FileName = "D:\setup.exe" 'DVD DRIVE
                '.FileName = "F:\setup.exe" 'EXTERNAL DRIVE
            End With
            .EnableRaisingEvents = True
            .Start()
            .WaitForExit()
            .Close()
            .Dispose()
        End With
        p = Nothing
        MsgBox("END")

    Catch ex As Exception
        MsgBox(ex.Message)

    End Try

End Sub

Upvotes: 1

Views: 88

Answers (1)

Hans Passant
Hans Passant

Reputation: 942267

This is a specific feature of installers, they copy themselves to the hard drive so they cannot fail when the user pops the drive while it is busy installing. That would be bad, leaving a partially installed app behind. This happens a lot more often than you might think, it is a classic "Oh no! Didn't mean to do that!" user response. Particularly back in the days when AutoRun still worked.

So what you see is what really happened. The process actually did quit, right after it started the copy on the hard drive. Nothing much you can do about it of course. Trying to find it back after it quits would be a workaround of sorts.

Upvotes: 2

Related Questions