0

I'm trying to run a set of testing/diagnostic programs in series, and no matter what I do, the all run concurrently. I'm assuming this is due to the code moving on as soon as the programs open, and then immediately do the next task in the sub. To give a little background, I had wrote a simple testing script in basic a while back, and now need to bring it current with a GUI. The batch file would open programs one after the other, because it would wait until an application would close before moving to the next line (unless using the start command).

Here is what I'm using in vb:

Private Sub btnRunselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRunselect.Click
    If cbDevmgr.Checked = True Then
        MessageBox.Show("DEVMGR!")
    End If
    If cbCamera.Checked = True Then
        MessageBox.Show("Camera!")
    End If
    If cbKeyboard.Checked = True Then
        MessageBox.Show("Keyboard!")
    End If
    If cbMic.Checked = True Then
        MessageBox.Show("Mic!")
    End If
    If cbBit.Checked = True Then
        MessageBox.Show("Bit!")
    End If
End Sub

That is with messagebox instead of the programs starting.

Now, the batch code is like this.

:run1

echo .
echo .
echo  ----------------------------------
echo .      Final Test
echo  ----------------------------------
echo .
echo .
SET %S="Final Test" 
\utils\nircmdc\nircmdc mutesysvolume 0
\utils\nircmdc\nircmdc setsysvolume 65535
set s=%s: =,%
\utils\nircmdc\nircmdc speak text %S%

    :: figure out where the batch drive is
    for %%a in (c,d,e,f,g,h,i,j) do if exist %%a:\BurnInTest\bit.exe set drv=%%a

    %drv%:


echo .
echo .
echo  ----------------------------------
echo.       Device Manager
echo  ----------------------------------
echo .
echo .

    cd C:\Windows\System32\
    devmgmt.msc
    cd \

    %drv%:


echo .
echo .
echo  ----------------------------------
echo.        Camera Test
echo  ----------------------------------
echo .
echo .
    \passmark\BurnInTest\AMCap\amcap.exe

echo .
echo .
echo  ----------------------------------
echo.           Keyboard Test
echo  ----------------------------------
echo .
echo .
    \passmark\BurnInTest\KeyboardTest\KeyboardTest.EXE -r

echo .
echo .
echo  ----------------------------------
echo.       Mic Test
echo  ----------------------------------
echo .
echo .
    \passmark\BurnInTest\SoundCheck\SoundCheck.EXE -R



    GOTO run6

Run6

Any help would be GREATLY appreciated! Thanks in advance.

  • How do you start the programs? Can you show the code that starts one of the programs? – Markus Dec 19 '13 at 19:56
  • I was starting the process like this: Process.Start("c:\Windows\System32\devmgmt.msc") I put the message boxes in as spacers while testing a few other features later in the program. I also tried defining the process with DIM xxxx AS NEW system.diagnostics.process string, but that did not work either. – user3120457 Dec 20 '13 at 00:35

1 Answers1

1

Have a look at the System.Diagnostics.Process.Start method. You could replace your MessageBox's with something like this instead:

 Dim P As New System.Diagnostics.Process()
 P.StartInfo.UseShellExecute = False
 P.StartInfo.FileName = "C:\\full\\path\\to.exe"
 P.StartInfo.Arguments = "arguments to pass to program"
 P.Start() ' or P.Start("C:\\full\\path\\to.exe", "arguments")
 P.WaitForExit()

That will start the program with arguments and wait for it to exit. There are timeout versions of the function if you don't want to wait indefinitely. If you don't call WaitForExit the process starts and program flow continues as normal. Here's some info on Process.StartInfo, UseShellExecute is true by default.

You can also use the Shell function in VB to start a process; aside from it returning a process ID (Process.Start returns true if it started) it is also 'less .NET' in that it's only available in the Visual Basic Runtime Library so if you ever switched to C#, you could still use the Process.Start 'out of the box' but would have to import the Microsoft.VistualBasic runtime (extra .DLL) to use the Shell function.

Here's a great answer as to why we need shell execute if you're curious on this too.

Hope that helps.

Community
  • 1
  • 1
txtechhelp
  • 6,625
  • 1
  • 30
  • 39
  • Thanks for the help, but that is what I was trying to do. The message boxes were just place holders while I was sorting out some other code further in the program. I'm not able to get waitforexit to work properly. I've tried adding it at the end of the process.start and as a separate line. I tried using the exact line you had mentioned, but to no avail. Any other suggestions? – user3120457 Dec 19 '13 at 23:59
  • I modified my answer for a different way to try the process start/wait as sometimes doing it inline like that can be potentially confusing (most notably the `UseShellExecute` line). – txtechhelp Dec 20 '13 at 01:01
  • Great! That worked. I'm not sure what I was doing wrong when I tried to declare my apps, but they work now. Thanks! Also, I'm curious, what is the use of the "useshellexecute = false" line? Wouldn't it default to that since your using start() rather than shell()? – user3120457 Dec 20 '13 at 02:46
  • I've edited my answer for some clarity on `Start` vs. `Shell` and the `UseShellExecute` :) – txtechhelp Dec 20 '13 at 07:55