VB6 Checkboxes to launch programs

Microsoft Visual basic enterprise 6.0 wi...
July 4, 2010 at 14:36:31
Specs: Windows 7 Pro (64-bit)
I am working on a program in vb6. What I am atempting to do is put a series of checkboxes which point to different programs. (I have already recompiled all of the programs so they are all silent installers and a single exe.) What I am attempting to do is insert a single command button that installs the checked programs. I do not want the programs to run at the same time though. Like this:

1) user clicks launch
2) program launches first checked box
3) program waits for first launch to finish
4) program launches second checked box
5) program waits for second launch to finish

Any assistance would be great.

See More: VB6 Checkboxes to launch programs

Report •

July 4, 2010 at 16:38:51
Normally any external event is triggered by VB it is run asynchronously. The is the even starts and VB carries on with what it was doing disregarding the event it started.

To make an event run synchronously, that is run and cause VB to pause until the event is completed you need to use the Wait for single object API.

You use the Create Process API to start the install then using the process handle returned. use the Wait for single object API to pause VB untill the preocess completes.


Hers the VB equivalent of the function prototype

Private Declare Function WaitForSingleObject Lib "Kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Microseconds should be set to


Report •

July 4, 2010 at 17:18:17
Ok, so on each of my checkboxes I can use a .vbs to wait for
a specified process. Like this (call it wait4process.vbs):

On Error Resume Next
If WScript.Arguments.Count <> 1 Then
blnRunning = True
Do While blnRunning = True
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name
from Win32_Process where Name='" & Wscript.Arguments(0)
& "'",,48)
blnRunning = False
For Each objItem in colItems
blnRunning = True
WScript.Sleep 30000
End If

then I would set each checkbox as follows:

Shell "_filepath\my.exe"
WScript.exe wait4process.vbs "my.exe"

If that looks right I just have to setup my command button to
trigger the installs. What command(s)/syntax do I use to
specified if checked run the script on the checkbox? Or,
would they still try to run at the same time?

Report •

July 4, 2010 at 17:59:46
Whatever you are doing its not going to work. You appear to be using VB6 as it it were VBS - different thing altogether. I have little experience with VBS so I cant help you there

The FSO was designed for VB Script, not VB6

Why you are calling a VBS from VB6 is a bit silly. You don't need VB Script at all.

I think a read of this on how to use the API from VB6 will help you:



Report •

Related Solutions

July 5, 2010 at 07:45:50
Ok, yeah I was not able to make that work. What i have now

Private Sub Command1_Click()

If Check1 = vbChecked Then Shell "Auto-
If Check2 = vbChecked Then Shell "Auto-
If Check3 = vbChecked Then Shell "Auto-Install\java.exe"
If Check4 = vbChecked Then Shell "Auto-Install\klite.exe"
If Check5 = vbChecked Then Shell "Auto-Install\msse.exe"
If Check6 = vbChecked Then Shell "Auto-
End Sub

This, as I expected (and StuartS stated) This works fine to
start the selected applications but It starts them all at once. I
would like for these applications to install one at a time. I
found some helpful info here: type=app&codeid=2">Here
I am looking into it now to see what I can do with it. Any
assistance would be great. Thanks

Report •

July 5, 2010 at 08:34:58
It's the Shell command that is the problem. It wont work in these circumstances.

You need to run the CreateProcess API to start the process. You then use the process handle returned to pause execution via the WaitForSingleObject API. it is the only way that you are going to pause a VB application for an indeterminate period.

You could use the Sleep API but that means predefining the pause period which may be too long or two short.

Here is a snippet of code that will point yo in the right direction:

Public Function SyncShell(CommandLine As String, Optional Timeout As Long, _
Optional WaitForInputIdle As Boolean, Optional Hide As Boolean = False) As Boolean

Dim hProcess As Long

Dim ret As Long
Dim nMilliseconds As Long

If Timeout > 0 Then
nMilliseconds = Timeout
nMilliseconds = INFINITE
End If

hProcess = StartProcess(CommandLine, Hide)

If WaitForInputIdle Then
'Wait for the shelled application to finish setting up its UI:
ret = InputIdle(hProcess, nMilliseconds)
'Wait for the shelled application to terminate:
ret = WaitForSingleObject(hProcess, nMilliseconds)
End If

CloseHandle hProcess

'Return True if the application finished. Otherwise it timed out or erred.
SyncShell = (ret = WAIT_OBJECT_0)
End Function

INFINITE is a constant with a value of -1

If you want to learn how to use the WaitForSingle object it is used on the Setup1.vbp application that comes with VB6. It is a good source of VB programming ideas.


Report •

July 6, 2010 at 17:29:39
Well I think I have a solution. It is a bit of a work around and
is the "cheating" way to do it but this is what I came up with:

I am using a string that adds the the following text for each
item checked:

start path\my.exe
WScript.exe wait4process.vbs"path\my.exe"

then saving as a batch file. then just launching the batch file.
I am sure I will get a few people correcting me saying this is
not the right way to do it. but IT WORKS! Stuart, thanks for
your assistance

Report •

Ask Question