How to execute multiple specific executables from VB.Net Core

deskcheck1-0579 411 Reputation points
2021-11-12T17:16:25.357+00:00

Hi,

Say I have 3 specific executables named: SWAT_123.exe, SWAT_456.exe, and SWAT_789.exe.

I want to call a subroutine in my module with following workflow:

RunCommand(SWAT_123.exe)  'run this in parallel
    When done,

RunCommand(SWAT_456.exe)  'run this in parallel
    When done,

RunCommand(SWAT_789.exe)  'run this in parallel
    When done

Close command prompt window
Exit application

I was trying to check when one process is done, but I have no way of knowing the current process by name or id because the process name returned is always "cmd" for all three processes.

Is there a way to do this in VB.Net?

Appreciate any help.

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
324 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,135 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 27,496 Reputation points Microsoft Vendor
    2021-11-15T07:49:09.187+00:00

    Hi @deskcheck1-0579 ,
    You can start the process and check when it exits by using Process Class.
    The following code displays the exit time and exit code at the end of each executable file by raising Process.Exited event.

        Sub Main()  
            Dim myProcess1 As Process = Process.Start("SWAT_123.exe")  
            myProcess1.EnableRaisingEvents = True  
            AddHandler myProcess1.Exited, AddressOf ProcessExited  
            Dim myProcess2 As Process = Process.Start("SWAT_456.exe")  
            myProcess2.EnableRaisingEvents = True  
            AddHandler myProcess2.Exited, AddressOf ProcessExited  
            Dim myProcess3 As Process = Process.Start("SWAT_789.exe")  
            myProcess3.EnableRaisingEvents = True  
            AddHandler myProcess3.Exited, AddressOf ProcessExited  
            Console.ReadKey()  
        End Sub  
        Friend Sub ProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)  
            Dim myProcess As Process = DirectCast(sender, Process)  
            MsgBox("The process " & myProcess.StartInfo.FileName & " exited at: " & myProcess.ExitTime & "." & System.Environment.NewLine & "Exit Code: " & myProcess.ExitCode)  
            myProcess.Close()  
    End Sub  
    

    Hope the code above could be helpful.
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful