Results 1 to 4 of 4

Thread: [RESOLVED] Pause application until process finished

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    313

    Resolved [RESOLVED] Pause application until process finished

    I've spent the last two hours trying to figure this one out,but no luck.
    Basicly it's pretty simple.When a button is clicked,my program gets the list of all Drives on a current computer.

    Then I use String.Concat to merge the drive letter and the rest of the path.
    So I get something like: "C:\" + "somefolder\somefile.some_extension"

    That creates a full path to a file I am looking for.Then I check if that file exists.If it doesn't exist,I use Process.Start to run the setup file(to install the program I need).

    It works well and installs the program I need.

    The Problem:
    I want my application,after the installation is finished,to check again if the program is installed and ofcourse confirm that it is.

    This is my code:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
         
            Dim DriveList As String() = Directory.GetLogicalDrives()
    
            Dim Drive, FullPath, Path1 As String
            Dim EmptyDrives As Integer
    
            Path1 = "wamp\wampmanager.exe"
            EmptyDrives = 0
    
            For Each Drive In DriveList
    
                FullPath = String.Concat(Drive, Path1)
                If File.Exists(FullPath) Then
                    MsgBox("Wamp server is installed and can be found at: " & FullPath)
                    Exit Sub
                Else
                    EmptyDrives = EmptyDrives + 1
                    If Directory.GetLogicalDrives.Count = EmptyDrives Then
                        Dim AppPath As String
                        AppPath = My.Application.Info.DirectoryPath
                        If MsgBox("We could not detect Wamp server on this machine!" & vbNewLine & "Would you like to install Wamp Server now?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                          
                            Process.Start(AppPath & "\WampServer20h.exe")
    
    
    
                        End If
    
                    End If
                End If
    
            Next Drive
    
    
    
        End Sub

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Pause application until process finished

    Replace this line:
    Code:
     Process.Start(AppPath & "\WampServer20h.exe")
    With this:
    Code:
     Process.Start(AppPath & "\WampServer20h.exe").WaitForExit()
    Then your app will block on that line until the process exits. Ideally you would do this in a background thread so that your application's user interface does not freeze but that may not matter that much in your case, I dont know.

    PS instead of using String.Concat to combine file paths, you can use the 'proper' method which is IO.Path.Combine
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    313

    Re: Pause application until process finished

    Thank you,it works!
    Resolved!

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Pause application until process finished

    No problem dont forget to mark the thread as resolved by using the Thread Tools menu at the top of the first post
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width