[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How can I code for ending a process?

Posted on 2002-06-03
11
Medium Priority
?
143 Views
Last Modified: 2010-05-02
I want to end a process that may or may not be running, much like I would do if I had to do it through task manager.  I do NOT want to end an application, but a process.  Example please...
0
Comment
Question by:jackjeckyl
[X]
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
  • 2
  • 2
  • 2
  • +4
11 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 7051824
Determine if an Application has Stopped Responding
http://www.thescarms.com/VBasic/AppResponse.asp

Other good process oriented examples here:
http://www.thescarms.com/vbasic/VBProcessRelated.asp
0
 
LVL 1

Expert Comment

by:jdc0724
ID: 7051949
Use WinAPI call "ExitProcess"  The exact declaration looks like this:

Declare sub ExitProcess Lib "Kernal32" (Byval uExitCode as Long).  

The specs also recommend posting a "WM_CLOSE" message to the main window of the application you wish to close.  This approach is apparently more politically correct then the "ExitProcess" suggestion I gave you first.
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7051972
>Use WinAPI call "ExitProcess"  The exact declaration looks like this:

That will exit the CALLING process, not a specified separate running/hung process as required.  It will also terminate your instance of VB if you execute it from the IDE.

>The specs also recommend posting a "WM_CLOSE" message

Yes, that is explained in the example I posted.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:jdc0724
ID: 7051985
Yes, that is correct.
0
 
LVL 1

Expert Comment

by:Toad224
ID: 7052512
perhaps try TerminateProcess if you want to kill another app...

Good luck!
0
 

Author Comment

by:jackjeckyl
ID: 7060096
I don't know API worth a crap.  All I know is the code runs fine, just doesn't work correctly.  It looks for a process ID, I'd like it to search the entire processes running by name (BAI_One.exe) and if it finds it, kills it.  Can it be done?  Code example descriptive please!
0
 

Author Comment

by:jackjeckyl
ID: 7060387
reposting question
0
 
LVL 4

Expert Comment

by:ravi_raj123
ID: 7167646
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long
Const PROCESS_ALL_ACCESS = &H1F0FFF

Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Sub EndTask(ProcID As Long)
   Dim lpExitCode As Long
   Dim lCode As Long
   On Error GoTo e
   lCode = OpenProcess(PROCESS_ALL_ACCESS, 0&, ProcID)
   If lCode = 0 Then
       'writeLog "Could not Aquire Process Context- Application may not be running"
       ''//Rjf Always start if not running
       'StartProc strFullKey, vbNormalFocus
       '//------v1.1.0
       'CleanUp ProcID, strFullKey ' Clean up
       'Exit Sub
   End If
   'writeLog "Got Process Context(" & lCode & ")- Retrieving Exit Code"
   GetExitCodeThread lCode, lpExitCode
   'writeLog "Terminating Process (" & lCode & ")- " & strFullKey
   If TerminateProcess(lCode, lpExitCode) Then
       'writeLog "Process Terminated"
       'StartProc strFullKey, vbNormalFocus
   Else
       'writeLog "Terminate Process Failed "
   End If
   'CleanUp ProcID, strFullKey
Exit Sub
e:
'writeLog Err.Description & " EndTask"
End Sub
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7897003
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- PAQ'd and points refunded
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

twalgrave
Cleanup Volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7941766
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 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