Article View: comp.lang.basic.visual.3rdparty
Article #98Re: HELP : Problem using shell
From: whigglesworth
Date: Mon, 19 Jul 1999 00:00
Date: Mon, 19 Jul 1999 00:00
133 lines
5124 bytes
5124 bytes
In article <932070223.927.48@news.remarQ.com>,
"Donald Stewart" <d.stewart@qcsllc.net> wrote:
>
> '***************************************************************
> 'Windows API/Global Declarations for :ExecCmd
> '***************************************************************
>
> Private Type STARTUPINFO
> cb As Long
> lpReserved As String
> lpDesktop As String
> lpTitle As String
> dwX As Long
> dwY As Long
> dwXSize As Long
> dwYSize As Long
> dwXCountChars As Long
> dwYCountChars As Long
> dwFillAttribute As Long
> dwFlags As Long
> wShowWindow As Integer
> cbReserved2 As Integer
> lpReserved2 As Long
> hStdInput As Long
> hStdOutput As Long
> hStdError As Long
> End Type
>
> Private Type PROCESS_INFORMATION
> hProcess As Long
> hThread As Long
> dwProcessID As Long
> dwThreadID As Long
> End Type
>
> Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal
hHandle
> As Long, ByVal dwMilliseconds As Long) As Long
>
> Private Declare Function CreateProcessA Lib "kernel32" (ByVal
> lpApplicationName As Long, ByVal lpCommandLine As String, ByVal
> lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal
> bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal
lpEnvironment
> As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As
STARTUPINFO,
> lpProcessInformation As PROCESS_INFORMATION) As Long
>
> Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long)
> As Long
> Private Const NORMAL_PRIORITY_CLASS = &H20&
> Private Const INFINITE = -1&
>
> Source Code:
> Note:This code is formatted to be pasted directly into VB.
> Pasting it into other editors may or may not work.
>
> '***************************************************************
> ' Name: ExecCmd
> ' Description:Wait for Shelled app to end
> This code will open Notepag by shelling it, and Then will wait until
it
> terminates to continue With the program. This is pretty cool,
although I
> have not been able to determine a lottle bug this program has. When
the
> program is shelled, the window dows not redraw until the shelled
application
> is terminated.
> ' By: Semin Nurkic
> '
> '
> ' Inputs:None
> '
> ' Returns:None
> '
> 'Assumes:None
> '
> 'Side Effects:None
> '
> 'Code provided by Planet Source Code(tm) (http://www.PlanetSource
> ' Code.com) 'as is', without warranties as to performance,
fitness,
> ' merchantability,and any other warranty (whether expressed or
impl
> ' ied).
> '***************************************************************
>
> Public Sub ExecCmd(cmdline$)
>
> Dim proc As PROCESS_INFORMATION
> Dim start As STARTUPINFO
> start.cb = Len(start)
> ' Shell the Application:
> ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&,
NORMAL_PRIORITY_CLASS,
> 0&, 0&, start, proc)
> ' Wait for the shelled application to finish:
> ret& = WaitForSingleObject(proc.hProcess, INFINITE)
> ret& = CloseHandle(proc.hProcess)
> End Sub
>
> Now place this code in the Form_Click Event of the Startup form:
> ExecCmd "notepad.exe"
> MsgBox "Notepad Terminated!", vbExclamation, "Terminated!"
>
> Hugo Palma wrote in message <3780FD98.33D7FD8E@mail.telepac.pt>...
> >I'm using the shell command to execute a certain program but shell
> >doesn't guarantee that the program will finish running when the next
> >instruction in the program code is executed.
> >How do i do, so that i can guarantee that the shell command finishes
and
> >only then will the program continue running ?
> >Thanks.
> >
If you are running the second program in another window, you can be
sure it runs without letting VB continue until the second proram loses
focus by doing this:
Dim vApp
vApp = Shell("pathname", vbMaximizedFocus)
AppActivate vApp, True
DoEvents
Whigglesworth
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Technical Details
Message-ID:
<7mvugq$5m8$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3780FD98.33D7FD8E@mail.telepac.pt> <932070223.927.48@news.remarQ.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1143a7,f86adbfa92df5e77 X-Google-Attributes: gid1143a7,public X-Google-Thread: f5f6f,f86adbfa92df5e77 X-Google-Attributes: gidf5f6f,public X-Google-Thread: 110e3b,f86adbfa92df5e77 X-Google-Attributes: gid110e3b,public X-Google-Thread: 107824,f86adbfa92df5e77 X-Google-Attributes: gid107824,public From: whigglesworth@my-deja.com Subject: Re: HELP : Problem using shell Date: 1999/07/19 Message-ID: <7mvugq$5m8$1@nnrp1.deja.com> X-Deja-AN: 502809847 References: <3780FD98.33D7FD8E@mail.telepac.pt> <932070223.927.48@news.remarQ.com> X-Http-Proxy: 1.1 x41.deja.com:80 (Squid/1.1.22) for client 209.37.240.53 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Mon Jul 19 19:32:42 1999 GMT X-MyDeja-Info: XMYDJUIDwhigglesworth Newsgroups: comp.lang.basic.visual.3rdparty,comp.lang.basic.visual.database,fj.comp.lang.visualbasic,comp.lang.basic.visual.misc X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)