Windows – Detecting Vista Starter three-open-app limit

vb6windows-vista

I'm working as a developer, curently mantaining a VB6 app that desperately needs to work fine under Vista. However, it must work fine under Vista Starter Edition, since is the version new computers here (Argentina) come with.

Now, onto the technical stuff: my app uses ImageMagick's convert to process images (resizing, black and white segmentation, rotation, etc), so the three-apps limit is a real pain in the… well, somewhere. Worst: the failure in running convert is not (currently?) detected, so when this happens the program hangs up.

Can anyone tell me how to:

a_ Detect the number of open apps, so I can ask the user to close something before retrying? An API call, maybe? or

b_ Detect that convert (currently running with the "Shell" function) wasn't launched properly?

Please, comments like "you should migrate your app to x" should be sent to my boss (not me), are not welcome and will make me travel to your place and bite your toe. It will take me some time to get the visa, though, but I assure you that one day a stranger will knock on your door, ask your StackOverflow username and then he WILL bite your toe.

Thanks for your consideration

Best Answer

Have you tried checking the return value of the Shell function? Documentation says it should return zero if the shell fails.


Martin says in the comments: I tried, but every time I check the return value, is some weird number greater than zero.

MarkJ again: The return values are supposed to be process IDs. It might be possible to make an API call to check whether they are valid process IDs. You could try something like this: this always shows a "succeeded" MsgBox for me, because I don't have Vista Starter Edition :)

Private Declare Function OpenProcess Lib "kernel32" ( _
    ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
    ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" ( _
    ByVal hObject As Long) As Long

Sub StartProcess()
   Dim ProcessId&
   Dim hProcess&
   Const PROCESS_QUERY_INFORMATION = &H400&

   ProcessId = Shell("notepad.exe", vbNormalFocus)
   hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
   If hProcess = 0& Then
     MsgBox "Failed"
   Else
     MsgBox "Succeeded"
     CloseHandle hProcess
   End If

End Sub