See Shell. See Shell run 
Author Message
 See Shell. See Shell run

I have on old dos program writen In QuickBasic 4.5

it does the following

1 Shell "AProg"
2 {Check files writen by AProg.exe}

when I convert to Visual Basic, The shell app runs but the original
program does not stop and thus, the files that need to be checked
are from the last time AProg ran.

what I need is

1 Shell "AProg"
2 {What untill AProg is no longer running}
2 {Check files writen by AProg.exe}

But I can't seem to come up with a fool proof method.
Is there a way in VB4 to "ask" windows what programs
are running?

                Thanks in advance,   Scott.



Tue, 04 May 1999 03:00:00 GMT  
 See Shell. See Shell run

Quote:
>what I need is
>1 Shell "AProg"
>2 {What until AProg is no longer running}
>3 {Check files writen by AProg.exe}

There are 3 methods;hoose the one for the OS and VB version being
used.  The 16 bit method is to call teh API GetModuleUsage.  The 2 32
bit methods are to use Shell and then call  OpenProcess and
GetExitcodeProcess, or start the app using CreateProcess and call
WaitForSingleObject.

If you specify the OS, I can be more specific.

Randy Birch
Microsoft MVP


Moderator, Fidonet Visual Basic Programmer's Conference

Visit VBnet at http://home.sprynet.com/sprynet/rasanen/



Wed, 05 May 1999 03:00:00 GMT  
 See Shell. See Shell run



Quote:
> >what I need is

> >1 Shell "AProg"
> >2 {What until AProg is no longer running}
> >3 {Check files writen by AProg.exe}

> If you specify the OS, I can be more specific.

VB4 & Windows 95.
And AProg = another VB4 prog.

        Thanks.                 Scott.



Wed, 05 May 1999 03:00:00 GMT  
 See Shell. See Shell run

I had a similar problem, however I was working with VB 1.00 at the time.
The Shell function is supposed to return the Task ID of the Task that is
starts. I used the IsTask() Win16 API function in a loop to check if the
Task ID became invalid, when it became invalid the Task was closed. I just
used a simple while loop and used the return value of IsTask() as the
condition. I also had to use the yield API call to give up time slices in
my polling loop.

I think the IsTask() API function has been removed from the Win32 API.

It looks like you could use the following API if you are coding for the
Win32 API. You call this function supplying the Process ID, and it will
return either the exit value of the process, or an indicator that it is
still running through lpdwExitCode.

BOOL GetExitCodeProcess(hProcess, lpdwExitCode)

   HANDLE hProcess;
   LPDWORD lpdwExitCode;

For further information look at PSS ID Number: Q108228 from Microsoft. If
you do a search of the Knowledge Base it might turn up.

----

Applications Development
======================
Mitchell Scientific, Inc.
PO Box 2605
Westfield, NJ 07091
Tel: (908) 654-9779
Fax: (908) 232-2216
http://www.mitchellscientific.com



Quote:
> I have on old dos program writen In QuickBasic 4.5

> it does the following

> 1 Shell "AProg"
> 2 {Check files writen by AProg.exe}

> when I convert to Visual Basic, The shell app runs but the original
> program does not stop and thus, the files that need to be checked
> are from the last time AProg ran.

> what I need is

> 1 Shell "AProg"
> 2 {What untill AProg is no longer running}
> 2 {Check files writen by AProg.exe}

> But I can't seem to come up with a fool proof method.
> Is there a way in VB4 to "ask" windows what programs
> are running?

>            Thanks in advance,   Scott.



Wed, 05 May 1999 03:00:00 GMT  
 See Shell. See Shell run

I've been using the following code from VB4-32 to wait for a shelled task
to end...  it seems a lot simpler than other methods I have seen and I'd
appreciate any comments on why it may not always work.  I suspect that it
may be ineffective for Windows NT systems but since I am using only Win95
currently I can't test that...
Declare Function GetModuleFileName Lib "kernel32" Alias
"GetModuleFileNameA"_
        (ByVal hModule As Long, ByVal lpFileName As String, _
        ByVal nSize As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub WaitForTaskEnd(hTask As Long) ' hTask is the return value from
SHELL
Dim strName As String * 512
Dim x As Long
Do
  x = GetModuleFileName(hTask, strName, x)
  If x > 0 Then Sleep 500&
Loop Until x < 1
End Sub



Quote:
> >what I need is
> >1 Shell "AProg"
> >2 {What until AProg is no longer running}
> >3 {Check files writen by AProg.exe}
> There are 3 methods;hoose the one for the OS and VB version being
> used.  The 16 bit method is to call teh API GetModuleUsage.  The 2 32
> bit methods are to use Shell and then call  OpenProcess and
> GetExitcodeProcess, or start the app using CreateProcess and call
> WaitForSingleObject.
> If you specify the OS, I can be more specific.
> Randy Birch
> Microsoft MVP

> Moderator, Fidonet Visual Basic Programmer's Conference
> Visit VBnet at http://home.sprynet.com/sprynet/rasanen/



Wed, 05 May 1999 03:00:00 GMT  
 See Shell. See Shell run

Here's a down and dirty way to do it:

The shell FUNCTION will return a windows task handle.
Save the handle in a global long and then you can use
a timer and in it's event do the following:

Sub Timer1_Timer
On Error Goto getout
AppActivate taskhandle
Exit Sub
getout:
timer1.enabled = false
{put your code for your second step here}
EndSub

Once the shelled program has ended, AppActivate will error
when it tries to execute, and then you can run your second
set of code.

This only works, of course, if you can have the shelled program
hog system focus.  If you want to do this in the background,
you will have to use some module specific API calls.

Mike



Quote:
> I have on old dos program writen In QuickBasic 4.5

> it does the following

> 1 Shell "AProg"
> 2 {Check files writen by AProg.exe}

> when I convert to Visual Basic, The shell app runs but the original
> program does not stop and thus, the files that need to be checked
> are from the last time AProg ran.

> what I need is

> 1 Shell "AProg"
> 2 {What untill AProg is no longer running}
> 2 {Check files writen by AProg.exe}

> But I can't seem to come up with a fool proof method.
> Is there a way in VB4 to "ask" windows what programs
> are running?

>            Thanks in advance,   Scott.



Mon, 10 May 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Shell program: running IE in Shell

2. Some weird run time error I've never seen before

3. Want To Run Excel and Access as ActiveX Objects Without Seeing Wa rning

4. Seeing if a given EXE is running

5. Seeing if a file/program is in memory/running

6. Seeing if a program is already running

7. Shell Function not shelling under Windows NT.

8. HELP WITH SHELL CODE - shell.txt (1/1)

9. HELP WITH SHELL CODE - shell.txt (0/1)

10. HELP WITH SHELL COMMAND - shell.txt (0/1)

11. Shell.Application.Count or Shell.Application.Contents.Count

12. Shell script - closing shell screen

 

 
Powered by phpBB® Forum Software