• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Program Not Terminating

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....
0
rajakhanna
Asked:
rajakhanna
1 Solution
 
rkot2000Commented:
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  
  Loop
 
End Sub
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
gbarenCommented:
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.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
mariab_Commented:
Hi,

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

...
0
 
CrazyOneCommented:
Yeah agree with mariab. You are better off using API calls when doing this instead of using the VB funcitions.
0
 
DanRollinsCommented:
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
0
 
Computer101Commented:
Comment from expert accepted as answer

Computer101
E-E Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now