Article View: comp.lang.basic.visual.3rdparty
Article #99Re: HELP : Problem using shell
From: Donald Stewart
Date: Thu, 15 Jul 1999 00:00
Date: Thu, 15 Jul 1999 00:00
120 lines
4585 bytes
4585 bytes
'***************************************************************
'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.
>
>Please reply by e-mail to
>hmpalma@mail.telepac.pt
>
>
Technical Details
Message-ID:
<932070223.927.48@news.remarQ.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3780FD98.33D7FD8E@mail.telepac.pt>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5f6f,f86adbfa92df5e77 X-Google-Attributes: gidf5f6f,public X-Google-Thread: 10b997,f86adbfa92df5e77 X-Google-Attributes: gid10b997,public X-Google-Thread: 110e3b,f86adbfa92df5e77 X-Google-Attributes: gid110e3b,public X-Google-Thread: 1143a7,f86adbfa92df5e77 X-Google-Attributes: gid1143a7,public X-Google-Thread: 107824,f86adbfa92df5e77 X-Google-Attributes: gid107824,public From: "Donald Stewart" <d.stewart@qcsllc.net> Subject: Re: HELP : Problem using shell Date: 1999/07/15 Message-ID: <932070223.927.48@news.remarQ.com> X-Deja-AN: 501460695 References: <3780FD98.33D7FD8E@mail.telepac.pt> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: newsabuse@remarQ.com X-Trace: 932070223.927.48 2JR3TALMD00000000 qube-03.us-ca.remarq.com Organization: Quality Control Services, Inc. NNTP-Posting-Date: Thu, 15 Jul 1999 20:23:43 GMT Newsgroups: comp.lang.basic.visual.3rdparty,comp.lang.basic.visual.database,fj.comp.lang.visualbasic,comp.lang.basic.visual.misc,it.comp.lang.visual-basic