Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Closing DOS windows opened with VBA Shell()


Message #1 by "Peter Richardson (Treetech)" <Peter.Richardson@t...> on Fri, 26 Oct 2001 18:07:15 +1300
I am using VBA Shell() to run a DOS batch file from within an Access 2000

DBMS. 

(It contains the DOS commands MODE COM1 ... and COPY ... COM1: to send ascii

files to a serial printer.)



Whatever I do I cannot get the minimized windows to close after the batch

file has been processed, which means closing them manually each time.



I have tried modifying the 'properties' dialog of the DOS window itself, and

I have @exit at the end of the batch file, but the DOS window will not

close! 



any ideas?



Peter Richardson

Te Teko

New Zealand



Message #2 by Walt Morgan <wmorgan@s...> on Fri, 26 Oct 2001 07:03:51 -0500
Include as the last line of your batch file the EXIT command. It will close

the dos window and return to the calling procedure.



Example:



abc.bat



cls

for %a in (*.*) do type %a

exit



Hope this helps,



Walt





Message #3 by "John Ruff" <papparuff@c...> on Fri, 26 Oct 2001 05:25:05 -0700



Peter,



I've never been able to get the DOS window to close either.  But I did

find that if I open the properties of the DOS program, go to the Program

Tab and make sure the Close on Exit box is checked, the program will

automatically close.  The drawback to this method is that if you move

the file from one directory to another, or to another computer, you must

remember to check the Close on Exit property of the file or it will

remain open once executed.



If anyone else knows of another method, I sure am interested also.



 

John Ruff - The Eternal Optimist :-) 





Message #4 by "Yehuda Rosenblum" <Yehuda@I...> on Fri, 26 Oct 2001 08:31:31 -0400
Why @exit?  As I remember the batch command to close is simply EXIT.  I

have an advanced set of VB codes that will do it, but does anyone know

if VBA will handle WinAPI's?



-----Original Message-----

From: Peter Richardson (Treetech)

[mailto:Peter.Richardson@t...]

Sent: Friday, October 26, 2001 1:07 AM

To: Access

Subject: [access] Closing DOS windows opened with VBA Shell()





I am using VBA Shell() to run a DOS batch file from within an Access

2000 DBMS.

(It contains the DOS commands MODE COM1 ... and COPY ... COM1: to send

ascii files to a serial printer.)



Whatever I do I cannot get the minimized windows to close after the

batch file has been processed, which means closing them manually each

time.



I have tried modifying the 'properties' dialog of the DOS window itself,

and I have @exit at the end of the batch file, but the DOS window will

not close!



any ideas?



Peter Richardson

Te Teko

New Zealand





---

You are currently subscribed to access as: yehuda@i... To

unsubscribe send a blank email to $subst('Email.Unsub')



Message #5 by Walt Morgan <wmorgan@s...> on Fri, 26 Oct 2001 07:55:08 -0500
John,



I'm somewhat confused (my normal state) regarding shutting down a DOS

window. I just created a short bat file with exit as the last command. I

created a form and put a controlbutton on it to execute the following:



dim x



x=Shell("MyDir\Test.Bat",vbMinimizedNoFocus)

form1.show



Test.Bat:



dir c:*.* /s /d

EXIT



When the code is run from VB the DOS window popsup and scrolls through the

harddrive and when finished the form reappears and the DOS window is gone.



Could the problem be with the way Access implements the DOS box?



Curious in Tennessee....



Regards,



Walt





Message #6 by "Pardee, Roy E" <roy.e.pardee@l...> on Fri, 26 Oct 2001 07:12:08 -0700
VBA will indeed do WinAPIs--as well as VB does anyway. 8^)



Roy Pardee

Programmer/Analyst

SWFPAC Lockheed Martin IT

Extension 8487



-----Original Message-----

From: Yehuda Rosenblum [mailto:Yehuda@I...]

Sent: Friday, October 26, 2001 5:32 AM

To: Access

Subject: [access] RE: Closing DOS windows opened with VBA Shell()





Why @exit?  As I remember the batch command to close is simply EXIT.  I

have an advanced set of VB codes that will do it, but does anyone know

if VBA will handle WinAPI's?



-----Original Message-----

From: Peter Richardson (Treetech)

[mailto:Peter.Richardson@t...] 

Sent: Friday, October 26, 2001 1:07 AM

To: Access

Subject: [access] Closing DOS windows opened with VBA Shell()





I am using VBA Shell() to run a DOS batch file from within an Access

2000 DBMS. 

(It contains the DOS commands MODE COM1 ... and COPY ... COM1: to send

ascii files to a serial printer.)



Whatever I do I cannot get the minimized windows to close after the

batch file has been processed, which means closing them manually each

time.



I have tried modifying the 'properties' dialog of the DOS window itself,

and I have @exit at the end of the batch file, but the DOS window will

not close! 



any ideas?



Peter Richardson

Te Teko

New Zealand
Message #7 by Dave Sharpe <pmmgpgp@y...> on Fri, 26 Oct 2001 12:28:04 -0700 (PDT)
Guys I think that I have sucessfully used the

technique

that MS details on the page below. I hope that it

addresses your problem.



Dave



=-=-=-=-



http://support.microsoft.com/support/kb/articles/Q129/7/96.ASP



The begin the discussion:

"Executing the Shell() function in a Visual Basic for

Windows program starts another executable program

asynchronously and returns control to the Visual Basic

application. This shelled program continues to run

independently of your application until the user

closes it.



However, if your Visual Basic application needs to

wait for the shelled process to terminate, you could

use the Windows API to poll the status of the

application, but this is not a very efficient

technique. The example in this article

demonstrates a better way."









--- "Pardee, Roy E" <roy.e.pardee@l...> wrote:

> VBA will indeed do WinAPIs--as well as VB does

> anyway. 8^)

> 

> Roy Pardee

> Programmer/Analyst

> SWFPAC Lockheed Martin IT

> Extension 8487

> 

> -----Original Message-----

> From: Yehuda Rosenblum

> [mailto:Yehuda@I...]

> Sent: Friday, October 26, 2001 5:32 AM

> To: Access

> Subject: [access] RE: Closing DOS windows opened

> with VBA Shell()

> 

> 

> Why @exit?  As I remember the batch command to close

> is simply EXIT.  I

> have an advanced set of VB codes that will do it,

> but does anyone know

> if VBA will handle WinAPI's?

> 

> -----Original Message-----

> From: Peter Richardson (Treetech)

> [mailto:Peter.Richardson@t...] 

> Sent: Friday, October 26, 2001 1:07 AM

> To: Access

> Subject: [access] Closing DOS windows opened with

> VBA Shell()

> 

> 

> I am using VBA Shell() to run a DOS batch file from

> within an Access

> 2000 DBMS. 

> (It contains the DOS commands MODE COM1 ... and COPY

> ... COM1: to send

> ascii files to a serial printer.)

> 

> Whatever I do I cannot get the minimized windows to

> close after the

> batch file has been processed, which means closing

> them manually each

> time.

> 

> I have tried modifying the 'properties' dialog of

> the DOS window itself,

> and I have @exit at the end of the batch file, but

> the DOS window will

> not close! 

> 

> any ideas?

> 

> Peter Richardson

> Te Teko

> New Zealand
Message #8 by "Pardee, Roy E" <roy.e.pardee@l...> on Fri, 26 Oct 2001 13:12:11 -0700
There's another potential solution to this at



http://members.home.net/r.pardee/WSHStuff.htm



(see the "Shell out to other programs synchronously" bit).



HTH,



-Roy



Roy Pardee

Programmer/Analyst

SWFPAC Lockheed Martin IT

Extension 8487



-----Original Message-----

From: Dave Sharpe [mailto:pmmgpgp@y...]

Sent: Friday, October 26, 2001 12:28 PM

To: Access

Subject: [access] RE: Closing DOS windows opened with VBA Shell()





Guys I think that I have sucessfully used the

technique

that MS details on the page below. I hope that it

addresses your problem.



Dave



=-=-=-=-



http://support.microsoft.com/support/kb/articles/Q129/7/96.ASP



The begin the discussion:

"Executing the Shell() function in a Visual Basic for

Windows program starts another executable program

asynchronously and returns control to the Visual Basic

application. This shelled program continues to run

independently of your application until the user

closes it.



However, if your Visual Basic application needs to

wait for the shelled process to terminate, you could

use the Windows API to poll the status of the

application, but this is not a very efficient

technique. The example in this article

demonstrates a better way."









--- "Pardee, Roy E" <roy.e.pardee@l...> wrote:

> VBA will indeed do WinAPIs--as well as VB does

> anyway. 8^)

> 

> Roy Pardee

> Programmer/Analyst

> SWFPAC Lockheed Martin IT

> Extension 8487

> 

> -----Original Message-----

> From: Yehuda Rosenblum

> [mailto:Yehuda@I...]

> Sent: Friday, October 26, 2001 5:32 AM

> To: Access

> Subject: [access] RE: Closing DOS windows opened

> with VBA Shell()

> 

> 

> Why @exit?  As I remember the batch command to close

> is simply EXIT.  I

> have an advanced set of VB codes that will do it,

> but does anyone know

> if VBA will handle WinAPI's?

> 

> -----Original Message-----

> From: Peter Richardson (Treetech)

> [mailto:Peter.Richardson@t...] 

> Sent: Friday, October 26, 2001 1:07 AM

> To: Access

> Subject: [access] Closing DOS windows opened with

> VBA Shell()

> 

> 

> I am using VBA Shell() to run a DOS batch file from

> within an Access

> 2000 DBMS. 

> (It contains the DOS commands MODE COM1 ... and COPY

> ... COM1: to send

> ascii files to a serial printer.)

> 

> Whatever I do I cannot get the minimized windows to

> close after the

> batch file has been processed, which means closing

> them manually each

> time.

> 

> I have tried modifying the 'properties' dialog of

> the DOS window itself,

> and I have @exit at the end of the batch file, but

> the DOS window will

> not close! 

> 

> any ideas?

> 

> Peter Richardson

> Te Teko

> New Zealand
Message #9 by Walt Morgan <wmorgan@s...> on Fri, 26 Oct 2001 16:25:10 -0500
Roy,



Thanks for sharing the WSHOM bit. It certainly is a cleaner way!



Regards,



Walt





Message #10 by "Alan Douglas" <acdoug@s...> on Sat, 27 Oct 2001 20:40:34
For the record, I copied the code from the KB article directly into a 

module in MS-Access 97, and, after declaring the variable 'ret' as Long, 

saw it work beautifully (I'm running Win98se on my PC). What a terrific 

tip!

... AL



> Guys I think that I have sucessfully used the

> technique

> that MS details on the page below. I hope that it

> addresses your problem.

> 

> Dave

> 

> =-=-=-=-

> 

> http://support.microsoft.com/support/kb/articles/Q129/7/96.ASP

> 

> The begin the discussion:

> "Executing the Shell() function in a Visual Basic for

> Windows program starts another executable program

> asynchronously and returns control to the Visual Basic

> application. This shelled program continues to run

> independently of your application until the user

> closes it.

> 

> However, if your Visual Basic application needs to

> wait for the shelled process to terminate, you could

> use the Windows API to poll the status of the

> application, but this is not a very efficient

> technique. The example in this article

> demonstrates a better way."

> 

> 

Message #11 by "Peter Richardson" <peter.richardson@t...> on Mon, 29 Oct 2001 09:45:26
Thanks to everyone who has provided suggestions on closing DOS windows. 

I'll try them out tomorrow, though I know already that checking the 'close 

automatically' checkbox in the DOS windows Properties doesn't make it 

close automatically, regardless of whether you launch the batchfile from 

the Start.. Run.. dialog or from within Access. I'll work through the 

other suggestions,



thanks again,

Peter Richardson




  Return to Index