I'm writing a small app to collect IE command diag. The problem is it's not waiting till the process finishes and it's errors out in the next line. My goal is to copy the log and paste it under a folder in Desktop

Try
            Process.Start("C:\Program Files\Internet Explorer\iediagcmd.exe")
            My.Computer.FileSystem.CopyFile(USERPROFILE & "\Desktop\IEDiag.cab", USERPROFILE & "\Desktop\W8\IEDiag.cab",
            Microsoft.VisualBasic.FileIO.UIOption.AllDialogs,
            Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
            My.Computer.FileSystem.DeleteFile(USERPROFILE & "\Desktop\IEDiag.cab")
            MsgBox("IE Logs copied sucessfully")
        Catch ex As Exception
            MsgBox("Error copying file: " & ex.Message)
        End Try

What am I doing wrong. And please bear in mind i'm a rookie in VB.

Thanks,

There are two ways to do it. First is to wait

copyProcess.Start("C:\Program Files\Internet Explorer\iediagcmd.exe")
copyProcess.WaitForExit(10000) ' Wait until finished or timeout after ten secs

for the process to exit.

Second is to wait event which a process raises when finished:

Private WithEvents copyProcess As Process ' Declare process

' Event handler for process exit
Private Sub copyProcess_Exited(sender As System.Object, e As System.EventArgs) Handles copyProcess.Exited
      ' Process finished
      ' Do the copy here after process finished
End Sub

' I started process from a button click but you can do it in some other way
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click

    ' Enable events
    copyProcess.EnableRaisingEvents = True
    ' Start process
    copyProcess.Start("C:\Program Files\Internet Explorer\iediagcmd.exe")

End Sub

HTH

commented: Thanks for the help. I can alway count on this community. +1

I'm trying the first method. But I get an error "Reference to a non shared member requires an object reference

here is the code:

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        Dim USERPROFILE As String
        USERPROFILE = Environ("HOMEPATH")
        IO.Directory.CreateDirectory(USERPROFILE & "\Desktop\W8")
        Dim strSysRoot As String
        strSysRoot = Environ("SystemRoot")
        USERPROFILE = Environ("HOMEPATH")
        Try
            Process.Start("C:\Program Files\Internet Explorer\iediagcmd.exe")
            Process.WaitForExit(10000)
            My.Computer.FileSystem.CopyFile(USERPROFILE & "\Desktop\IEDiag.cab", USERPROFILE & "\Desktop\W8\IEDiag.cab",
            Microsoft.VisualBasic.FileIO.UIOption.AllDialogs,
            Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
            My.Computer.FileSystem.DeleteFile(USERPROFILE & "\Desktop\IEDiag.cab")
            MsgBox("IE Logs copied sucessfully")
        Catch ex As Exception
            MsgBox("Error copying file: " & ex.Message)
        End Try

Sorry got it to work.

Declared it first
Dim myProcess As Process = System.Diagnostics.Process.Start("C:\Program Files\Internet Explorer\iediagcmd.exe")

Then used myProcess.WaitForExit()now it works

Thanks for the help mate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.