Go Premium for a chance to win a PS4. Enter to Win


Program Not Terminating

Posted on 2001-06-20
Medium Priority
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

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.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

mariab_ earned 720 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

876 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