|
-
Jan 24th, 2010, 12:49 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] how to kill process immidietly
what i want is not postmessage, because that let the app
close it self,
what i need is the way the taskmanager kill a process.
it just kill it and the killed app doesn't get message of closing.
right now i found that if i make an app child of my window,
i can then destroy it,
so that's how i'm doing it right now, make it child and kill it,
but i wonder if there is more direct way to do that,
maybe straight API ?
-
Jan 24th, 2010, 12:59 PM
#2
Re: how to kill process immidietly
Search for TerminateProcess.
-
Jan 24th, 2010, 01:06 PM
#3
Thread Starter
Hyperactive Member
Re: how to kill process immidietly
i already tried it, but it didn't work for external app.
am i missing something ?
-
Jan 24th, 2010, 01:19 PM
#4
Lively Member
Re: how to kill process immidietly
 Originally Posted by whatsup
what i want is not postmessage, because that let the app
close it self,
what i need is the way the taskmanager kill a process.
it just kill it and the killed app doesn't get message of closing.
right now i found that if i make an app child of my window,
i can then destroy it,
so that's how i'm doing it right now, make it child and kill it,
but i wonder if there is more direct way to do that,
maybe straight API ?
u can use this code
Code:
shell ("taskkill.exe /IM appnametokill.exe /F")

Im Pro in C#,VB.NET,Batch,Socket Programming, SPY Software Programming, VB6, Win32Api, VBscript, Windows Registry, ASP.NET, PHP, Jquery, AJAX.
-
Jan 24th, 2010, 01:23 PM
#5
Lively Member
Re: how to kill process immidietly

Im Pro in C#,VB.NET,Batch,Socket Programming, SPY Software Programming, VB6, Win32Api, VBscript, Windows Registry, ASP.NET, PHP, Jquery, AJAX.
-
Jan 24th, 2010, 01:29 PM
#6
Thread Starter
Hyperactive Member
Re: how to kill process immidietly
 Originally Posted by agent_007
u can use this code
Code:
shell ("taskkill.exe /IM appnametokill.exe /F")
thank you very much for that.
tough it's not an API,
but in the begining i was looking for a way to do that from the command line.
-
Jan 24th, 2010, 01:30 PM
#7
Lively Member
Re: how to kill process immidietly
if that solved ur problem than mark the post as Resolved

Im Pro in C#,VB.NET,Batch,Socket Programming, SPY Software Programming, VB6, Win32Api, VBscript, Windows Registry, ASP.NET, PHP, Jquery, AJAX.
-
Jan 24th, 2010, 03:37 PM
#8
Thread Starter
Hyperactive Member
Re: how to kill process immidietly
mm
i was wondering about API to to that.
so i'll wait maybe someone will come with something.
-
Jan 25th, 2010, 01:34 AM
#9
Member
Re: how to kill process immidietly
Hi
I had a similar problem with MS Office 2007 not quitting out and still running in the taskmanager witch was causing havoc. This is the code i used
Please note this code was called in MS Access to Quit out MS Excel that MS Access started the instance of.
Code:
Sub TerminateXLProcess()
Dim strTerminateThis As String 'The variable to hold the process to terminate
Dim objWMIcimv2 As Object
Dim objProcess As Object
Dim objList As Object
Dim intError As Integer
strTerminateThis = "Excel.exe" 'Process to terminate,
Set objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2") 'Connect to CIMV2 Namespace
Set objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='" & strTerminateThis & "'") 'Find the process to terminate
If objList.Count = 0 Then 'If 0 then process isn't running
Exit Sub
Else
For Each objProcess In objList
intError = objProcess.Terminate 'Terminates a process and all of its threads.
'Return value is 0 for success. Any other number is an error.
If intError <> 0 Then
MsgBox "ERROR: Unable to terminate that process.", vbCritical, "Aborting"
Exit Sub
End If
Next
'ALL instances of specified process (strTerminateThis) has been terminated
End If
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
Exit Sub
End Sub
Hope this helps
Snowie
-
Jan 25th, 2010, 04:02 PM
#10
Re: how to kill process immidietly
 Originally Posted by Snowie
Hi
I had a similar problem with MS Office 2007 not quitting out and still running in the taskmanager witch was causing havoc. This is the code i used
Please note this code was called in MS Access to Quit out MS Excel that MS Access started the instance of.
While that code might be useful for others, you should never have used it yourself - instead you should have fixed the mistakes in your code that caused Excel to stay open in the first place (rather than force an instance of Excel to close, which might be a user initiated one with unsaved work).
There is a general guide on how to fix those mistakes in post #11 of my Excel automation tutorial (link in my signature). If you want more specific help then create a thread, and feel free to PM me a link to it.
-
Jan 25th, 2010, 11:01 PM
#11
Member
Re: how to kill process immidietly
Hi
I had a problem with the save cmd in excel. When I quit it with out saving it closed down. But if I saved the doc then closed it it would leave the processing running. I had a few other people look at my code and couldn't find a problem with it. I even tried opening the doc and closing it and still had the same issue. This went on for 3 days and this was the only work around I found 
Cheers snow
-
Jan 26th, 2010, 11:21 AM
#12
Re: how to kill process immidietly
I have a success rate that is very near 100%... and based on what you've posted the issue should be easy to find.
The section about it in my tutorial explains the methods I use, but feel free to post a new thread as I said before (with the text you just posted, and the code).
-
Jan 26th, 2010, 01:11 PM
#13
Member
Re: how to kill process immidietly
You up to the challange then? I can post you the code for a look it's very short
-
Jan 26th, 2010, 01:17 PM
#14
Re: how to kill process immidietly
I clearly am based on my earlier posts - so as I have said, create a new thread (we don't want to derail this one any further).
-
Jan 26th, 2010, 01:33 PM
#15
Member
Re: how to kill process immidietly
Ok I'll fire up a new thread
-
Jan 30th, 2010, 12:27 PM
#16
Thread Starter
Hyperactive Member
Re: how to kill process immidietly
i found the answer accidentally, in anti-virus source code
Code:
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function GetCurrentProcess Lib "kernel32" () As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, lpdwprocessid As Long) As Long
Public Sub MyKillProcess()
Dim lNum1 As Long
Call GetWindowThreadProcessId(FocusedHwnd, lNum1)
lNum1 = OpenProcess(PROCESS_ALL_ACCESS, 0, lNum1)
Call TerminateProcess(lNum1, 0&)
Call CloseHandle(lNum1)
End Sub
thanks again to everyone tried to help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|