Program Not Terminating

Posted on 2001-06-20
Last Modified: 2010-05-02
I made a VB Program which uses Shell Function to invoke some another program .That another Program is terminated automatically...

If i run this VB Exe on WinNt then the program is running fine.. it invokes that another program.. run it in the background.. close that program.. and then come out from the VB Exe...

But i run this same VB Exe on Win2000 Server the program invokes that another program... and it come out from the VB Exe leaving that program in the Background....

So Pl tell why it is not terminating that another program automatically.. Need to do some settings....or write something special in VB Program

Besides the terminating the task performed by that another program goes fine....
Question by:rajakhanna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6210274
i am using the following code on nt to control another program. I did not try on 2000.

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub ShellIBI(ByVal lvsShell As String, _
                    ByVal lvsFocusWindows As String)
  Dim lvlProcessID As Long
  Dim lvlProcessHhd As Long
  Dim lvtStarted As Date
  Dim lasWindows() As String
  Dim i As Long
  Dim lvfFound As Boolean
  Dim lvfTimeout As Boolean
  Dim lvlhWnd As Long
  Dim lvlTemp As Long
  Dim lvlTimes As Long
  Dim lvfFirstWindow As Boolean
  lvlProcessID = Shell(lvsShell , vbMinimizedNoFocus)
  'get process handle
  lvlProcessHhd = OpenProcess(SYNCHRONIZE, True, lvlProcessID)
  'wait for terminate process here
  lvlTemp = WaitForSingleObject(lvlProcessHhd, 50)
  Do While lvlTemp <> 0
    lvlTemp = WaitForSingleObject(lvlProcessHhd, 50)
    Sleep 50  
End Sub
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6210297

Expert Comment

ID: 6210540
Use the WSH Run instead of Shell. The Run has a Wait parameter, which will cause the program to halt until the called program terminates.

Include a reference to Windows Script Host Object Model and use code like this:

    Dim oShell As New IWshShell_Class
    oShell.Run sCommand, 1, True

The third parameter in oShell.Run specifies that this code should not continue until sCommand is finished.

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.


Accepted Solution

mariab_ earned 180 total points
ID: 6210771

try using ShellExecute I have tried in Win2000 and NT4 - it works just fine!

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWMINNOACTIVE = 7 ' just for sample you could use another constant - 0 for example


strProgramName = "d:\games\brood_war\brood.exe" ' :))

ShellExecute 0, "open", strProgamName, "", "", SW_SHOWMINNOACTIVE

LVL 44

Expert Comment

ID: 6213024
Yeah agree with mariab. You are better off using API calls when doing this instead of using the VB funcitions.
LVL 49

Expert Comment

ID: 7139583
Hi rajakhanna,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept mariab_'s comment(s) as an answer.

rajakhanna, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7173279
Comment from expert accepted as answer

E-E Moderator

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question