'shell'ing a external windows program withoud windows 
Author Message
 'shell'ing a external windows program withoud windows

Greetings to All.

I'm quite new to Visual Basic, so could somebody plese help me with
this?

I need to 'spawn' a program from Visual Basic, and let the
'father-process' wait for the program to die.

Althou the external program is a 'windows program' (it uses winsock,
and therefore needs windows to run), it doesn't open a window or
something like that.
It just takes some parameters and generates a file with the output.

(Actually the program is just a 'port' of a unix-utility 'ldapsearch',
which takes some command-line parameters, performs a LDAP (X.500 over
IP) query and outputs it to standard-out.
I mearly modified the program so it sends its data to a file in stead
of standard-out).

The problem is this:
I've found that (using 'shell') one start an external program. The
problem that 'shell' start a program asyncronously.
This means that I need some way to see if my 'child-program' has
finnish or not.

There are some examples in the manuals, but these are all programs
which have their own windows (and apparently, communication with other
programs happen is based on 'window-names'). ("AppActivate").

Can anybody help me?

Cheerio! Kr. Bonne.

---
Kristoff Bonne, Belgacom IS-TelaneT           Netwerk Planning en -
-Beheer
(C=BE;A=RTT;P=RTTIPC;S=Bonne;G=Kristoff)      fax         :  +32 2
2025590

615492
                 **** #include <standard/disclamer.h> ****

---
Kristoff Bonne, Belgacom IS-TelaneT           Netwerk Planning en - Beheer
(C=BE;A=RTT;P=RTTIPC;S=Bonne;G=Kristoff)      fax         :  +32 2 2025590

                 **** #include <standard/disclamer.h> ****



Sat, 20 Jun 1998 03:00:00 GMT  
 'shell'ing a external windows program withoud windows

Quote:

> Greetings to All.

> I'm quite new to Visual Basic, so could somebody plese help me with
> this?

> I need to 'spawn' a program from Visual Basic, and let the
> 'father-process' wait for the program to die.

> Althou the external program is a 'windows program' (it uses winsock,
> and therefore needs windows to run), it doesn't open a window or
> something like that.
> It just takes some parameters and generates a file with the output.

> (Actually the program is just a 'port' of a unix-utility 'ldapsearch',
> which takes some command-line parameters, performs a LDAP (X.500 over
> IP) query and outputs it to standard-out.
> I mearly modified the program so it sends its data to a file in stead
> of standard-out).

> The problem is this:
> I've found that (using 'shell') one start an external program. The
> problem that 'shell' start a program asyncronously.
> This means that I need some way to see if my 'child-program' has
> finnish or not.

> There are some examples in the manuals, but these are all programs
> which have their own windows (and apparently, communication with other
> programs happen is based on 'window-names'). ("AppActivate").

> Can anybody help me?

> Cheerio! Kr. Bonne.

Kristoff:

Put this in your global declarations module:
Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)

Then in your code, store the task ID that is returned when you shell an app:
lTaskID = Shell("calc.exe", vbNormalFocus)

All you have to do now is loop:
Do Until GetModuleUsage(lTaskID) <= 0
  DoEvents
Loop

When the returned value is <= 0, the shelled app is no longer running.
I believe this API function works even if the shelled app has no window.

Hope this helps.

Sean Dillon



Sat, 20 Jun 1998 03:00:00 GMT  
 'shell'ing a external windows program withoud windows
Regarding waiting for a shelled process to end:  (Is there a FAQ for this
thing?)

Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer) As Integer

X%=Shell("appname")
While GetModuleUsage(X%) <> 0
  DoEvents
Wend

David

Quote:

>Subject: 'shell'ing a external windows program withoud windows
>Date: Tue, 02 Jan 1996 14:22:07 GMT
>Greetings to All.
>I'm quite new to Visual Basic, so could somebody plese help me with
>this?
>I need to 'spawn' a program from Visual Basic, and let the
>'father-process' wait for the program to die.



Sat, 20 Jun 1998 03:00:00 GMT  
 'shell'ing a external windows program withoud windows
re waiting for a shelled process to finish:

Quote:
>Put this in your global declarations module:
>Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)
>Then in your code, store the task ID that is returned when you shell an app:
>lTaskID = Shell("calc.exe", vbNormalFocus)

>All you have to do now is loop:
>Do Until GetModuleUsage(lTaskID) <= 0
>  DoEvents
>Loop

jens suggested this be "<>" instead of "<="     I think he is correct.

Davud



Sat, 20 Jun 1998 03:00:00 GMT  
 'shell'ing a external windows program withoud windows


Quote:
>All you have to do now is loop:
>Do Until GetModuleUsage(lTaskID) <= 0

Sometime GetModuleUsage drops below 0, so this should be:

Do Until GetModuleUsage(lTaskID) = 0

or

Do While GetModuleUsage(lTaskID) <> 0

Jens
--
* Everything I said are the opinions of someone else.   *
* I just cut-and-pasted.                                *

Jens Balchen jr.       http://www.sn.no/~balchen



Sat, 20 Jun 1998 03:00:00 GMT  
 'shell'ing a external windows program withoud windows

writes:

Quote:

> re waiting for a shelled process to finish:

> >Put this in your global declarations module:
> >Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)

> >Then in your code, store the task ID that is returned when you shell an app:
> >lTaskID = Shell("calc.exe", vbNormalFocus)

> >All you have to do now is loop:
> >Do Until GetModuleUsage(lTaskID) <= 0
> >  DoEvents
> >Loop

> jens suggested this be "<>" instead of "<="     I think he is correct.

No. It should be "=" if you use "Do Until". "<>" is for "Do
While" (as Jens said).

 _  _____  _   _

| || (_) || `\| |
| ||  _  || , ` | If they give you lined paper, write the other way!
| || | | || |`\ |
(_)(_) (_)(_) (_) http://www.sn.no/~balchen/igloo/



Sun, 21 Jun 1998 03:00:00 GMT  
 'shell'ing a external windows program withoud windows
: Put this in your global declarations module:
: Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)

: Then in your code, store the task ID that is returned when you shell an app:
: lTaskID = Shell("calc.exe", vbNormalFocus)
:  
: All you have to do now is loop:
: Do Until GetModuleUsage(lTaskID) <= 0
:   DoEvents
: Loop

"GetModuleUsage" is no longer supported with "kernal32".  Has anyone
worked out a way of doing this with VBasic 4.0 when writing 32-bit apps?

--
Dean C. Sullinger

Holy Bible Web and Salvation can be found at: http://www.crl.com/~deans



Fri, 26 Jun 1998 03:00:00 GMT  
 'shell'ing a external windows program withoud windows

Quote:


> : Put this in your global declarations module:
> : Declare Function GetModuleUsage% Lib "Kernel" (ByVal hModule%)

> : Then in your code, store the task ID that is returned when you shell an app:
> : lTaskID = Shell("calc.exe", vbNormalFocus)
> :
> : All you have to do now is loop:
> : Do Until GetModuleUsage(lTaskID) <= 0
> :   DoEvents
> : Loop

> "GetModuleUsage" is no longer supported with "kernal32".  Has anyone
> worked out a way of doing this with VBasic 4.0 when writing 32-bit apps?

> --
> Dean C. Sullinger

> Holy Bible Web and Salvation can be found at: http://www.crl.com/~deans

Dean,

You can use the Win32 API call CreateProcess to shell the application
and then if it is a 32bit app you can use WaitForSingleObject or
GetExitCodeProcess to detect when it has finished.  These calls cannot
be used for 16bit apps so I have had to use FindWindow.  Microsoft
Knowledge Base article Q129796 refers!

regards

Jon Beets



Sun, 28 Jun 1998 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. 'Poke'ing and 'peek'ing other process's memory in VB6

2. 'Shell'ing MS Excel in Win95

3. 'end'ing my program

4. Passing window.external to OCX (VB6) (or way of retrieving window.external like in C++ ServiceProvider)

5. Shell'ing output to a file?

6. Does anybody know how to make an external applicatoin's window always stay on top

7. Show a window from shell's namespace?

8. Why windows won't close after shell process

9. closing dos app's window after shell

10. Bringing 'Shelled' programs to the front

11. Problems with 'shelling' to Dos program

12. Login Off's In Windows '95/'98

 

 
Powered by phpBB® Forum Software