I have problem using function "Shell" 
Author Message
 I have problem using function "Shell"

I m trying to execute an executable file (.exe) from VB. The problem is
that the function "Shell" executes the said file but as another thread
and after generating that thread the control is transfer to the very
next statement after "Shell" and that statement starts execution, which
is not desired. I want that the function "Shell" should complete its
execution and then next statement should start. Is there any solution
to this problem? If anybody knows about ... please let me know

I'll grateful!

Ustaad

--== Sent via Deja.com http://www.*-*-*.com/
---Share what you know. Learn what you don't.---



Sat, 03 Nov 2001 03:00:00 GMT  
 I have problem using function "Shell"
When you use the shell command, the Double-type number that is returned
to it can be used to find out if the window is still active.  The
number that is returned should be a unique number relating to the hWnd
of the window you just started.  You can then enumerate through the
Windows Open handles (API Call) to find out if your window is still
open.

KB article #Q129796 about this on the Microsoft Support Site will tell
you how to do this.

Late,

Mark Gerlach


Quote:

> I m trying to execute an executable file (.exe) from VB. The problem
is
> that the function "Shell" executes the said file but as another thread
> and after generating that thread the control is transfer to the very
> next statement after "Shell" and that statement starts execution,
which
> is not desired. I want that the function "Shell" should complete its
> execution and then next statement should start. Is there any solution
> to this problem? If anybody knows about ... please let me know

> I'll grateful!

> Ustaad

> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


Sat, 03 Nov 2001 03:00:00 GMT  
 I have problem using function "Shell"

Quote:
> I want that the function "Shell" should complete its
>execution and then next statement should start. Is there any solution
>to this problem? If anybody knows about ... please let me know

I found code in the MS Knowledge base that did this.   Look for a
reference to "ExecCmd".  Cut and paste into my VB app worked like a
champ.

I ended up creating a tiny batch file with the name of the DOS fortran
.EXE and any command line arguments, and executing it from within VB5
or 6 with the statement:

    ExecCmd CmdStr & " /C " & TmpBat

where CmdStr = "command.com"  for Win95, Win98  or  "cmd.exe" for
WinNT  and TmpBat is the path and name of the tiny batch file.

It opens a DOS window, and closes it when finished.  You can add a
Pause line in the .bat file to keep the window open when the program
finishes.

HTH
--
Duncan



Sat, 03 Nov 2001 03:00:00 GMT  
 I have problem using function "Shell"
Use this:

Option Explicit
Private Type STARTUPINFO
  cb As Long
  lpReserved As Long
  lpDesktop As Long
  lpTitle As Long
  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 ' VB pads integers so we use bytes instead
  bytShowWindow1 As Byte
  bytShowWindow2 As Byte
' cbReserved2 As Integer
  bytReserved21 As Byte
  bytReserved22 As Byte
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
End Type
Private Type SECURITY_ATTRIBUTES
  nLength As Long
  lpSecurityDescriptor As Long
  bInheritHandle As Long
End Type
Private Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessId As Long
  dwThreadId As Long
End Type
' note: lpProcessAttributes and lpThreadAttributes are normally
' defined as SECURITY_ATTRIBUTES - this example uses AS ANY in order
' to be able to pass "ByVal 0&" to use all defaults
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA"
_
  (ByVal lpApplicationName As String, ByVal lpCommandLine As String, _
  lpProcessAttributes As Any, lpThreadAttributes As Any, _
  ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long,
lpEnvironment As Any, _
  ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, _
  lpProcessInformation As PROCESS_INFORMATION) As Long
Private Const INFINITE = -1
Private Const STARTF_USESHOWWINDOW = &H1
Private Const STARTF_USESIZE = &H2
Private Const STARTF_USEPOSITION = &H4
Private Const STARTF_USECOUNTCHARS = &H8
Private Const STARTF_USEFILLATTRIBUTE = &H10
Private Const STARTF_RUNFULLSCREEN = &H20
Private Const STARTF_FORCEONFEEDBACK = &H40
Private Const STARTF_FORCEOFFFEEDBACK = &H80
Private Const STARTF_USESTDHANDLES = &H100
Private Const STARTF_USEHOTKEY = &H200
Private Declare Function GetExitCodeProcess Lib "kernel32" _
  (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
  (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Function ShellWait(ByVal CommandLine As String, _
  ByVal ShowWindow As Long, _
  ExitCode As Long) As Long
Dim hTask As Long
Dim lExitCode As Long
Dim udtSI As STARTUPINFO
Dim udtPI As PROCESS_INFORMATION
Dim x As Long
ShellWait = False
On Error Resume Next
udtSI.cb = LenB(udtSI)
udtSI.dwFlags = STARTF_USESHOWWINDOW
udtSI.bytShowWindow1 = ShowWindow And 255
udtSI.bytShowWindow2 = (ShowWindow \ 256) And 255
hTask = CreateProcess(vbNullString, CommandLine, ByVal 0&, _
  ByVal 0&, False, 0, ByVal 0&, vbNullString, udtSI, udtPI)
If Err.Number <> 0 Then Exit Function
Call WaitForSingleObject(udtPI.hProcess, INFINITE)
x = GetExitCodeProcess(udtPI.hProcess, lExitCode)
ExitCode = lExitCode
ShellWait = True
End Function

Quote:

>I m trying to execute an executable file (.exe) from VB. The problem is
>that the function "Shell" executes the said file but as another thread
>and after generating that thread the control is transfer to the very
>next statement after "Shell" and that statement starts execution, which
>is not desired. I want that the function "Shell" should complete its
>execution and then next statement should start. Is there any solution
>to this problem? If anybody knows about ... please let me know

>I'll grateful!

>Ustaad

>--== Sent via Deja.com http://www.deja.com/ ==--
>---Share what you know. Learn what you don't.---



Sun, 04 Nov 2001 03:00:00 GMT  
 I have problem using function "Shell"
I dealt once with this issue in the following way:
Dim lhandle as long
shell("MyApplication")
while (GetModuleHandle("MyApplication") )
    DoEvents
    'Since it is loop it will chew quite of CPU cycle, but it works.
wend
Quote:

>I m trying to execute an executable file (.exe) from VB. The problem is
>that the function "Shell" executes the said file but as another thread
>and after generating that thread the control is transfer to the very
>next statement after "Shell" and that statement starts execution, which
>is not desired. I want that the function "Shell" should complete its
>execution and then next statement should start. Is there any solution
>to this problem? If anybody knows about ... please let me know

>I'll grateful!

>Ustaad

>--== Sent via Deja.com http://www.deja.com/ ==--
>---Share what you know. Learn what you don't.---



Sun, 04 Nov 2001 03:00:00 GMT  
 I have problem using function "Shell"
Using ::WaitForSingleObject will put asleep the thread that is calling this
function. Since VB is a single threaded tool, the application that creates
the other process will be not responsive.
Quote:

>I m trying to execute an executable file (.exe) from VB. The problem is
>that the function "Shell" executes the said file but as another thread
>and after generating that thread the control is transfer to the very
>next statement after "Shell" and that statement starts execution, which
>is not desired. I want that the function "Shell" should complete its
>execution and then next statement should start. Is there any solution
>to this problem? If anybody knows about ... please let me know

>I'll grateful!

>Ustaad

>--== Sent via Deja.com http://www.deja.com/ ==--
>---Share what you know. Learn what you don't.---



Sun, 04 Nov 2001 03:00:00 GMT  
 I have problem using function "Shell"


Quote:
>Using ::WaitForSingleObject will put asleep the thread that is calling this
>function. Since VB is a single threaded tool, the application that creates
>the other process will be not responsive.

That may or may not be a problem.  If it is, you can always set the
second parameter to something other than INFINITE so that it returns
control to the calling prog.  You can put the WaitForSingleObject code
in a loop and test the return to see if it is finished.  Putting
DoEvents in the loop makes sure that the program remains more or less
responsive to system events.

Paul Hewson  paulh(a)vif.*Delete*This*.com
-------------------------------------------
  e-mail altered to foil auto-spammers  

-------------------------------------------
I used to work in a fire hydrant factory.  You couldn't park
anywhere near the place.
--Steven Wright



Wed, 07 Nov 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Having problems with "Insert Into" command

2. Looking for "Shell" like function

3. Synchronized problem about "SHELL command"

4. Problem With "window.showmodaldialog("")"

5. Datatype mismatch using "UCase" function

6. Using "age" function in Word form

7. Using Dos's "truename" function

8. using the api function "UpdateWindow".

9. DatePart Function "yy" problem

10. "Function address" problem

11. Problems regarding "Round" function

12. Problems with the "Now" function

 

 
Powered by phpBB® Forum Software