Results 1 to 16 of 16

Thread: [RESOLVED] how to kill process immidietly

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Resolved [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 ?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to kill process immidietly

    Search for TerminateProcess.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: how to kill process immidietly

    i already tried it, but it didn't work for external app.
    am i missing something ?

  4. #4
    Lively Member agent_007's Avatar
    Join Date
    Jan 2010
    Posts
    93

    Re: how to kill process immidietly

    Quote Originally Posted by whatsup View Post
    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.

  5. #5
    Lively Member agent_007's Avatar
    Join Date
    Jan 2010
    Posts
    93

    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: how to kill process immidietly

    Quote Originally Posted by agent_007 View Post
    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.

  7. #7
    Lively Member agent_007's Avatar
    Join Date
    Jan 2010
    Posts
    93

    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.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    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.

  9. #9
    Member
    Join Date
    Jan 2010
    Posts
    48

    Smile 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

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: how to kill process immidietly

    Quote Originally Posted by Snowie View Post
    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.

  11. #11
    Member
    Join Date
    Jan 2010
    Posts
    48

    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

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: how to kill process immidietly

    I have a success rate that is very near 100&#37;... 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).

  13. #13
    Member
    Join Date
    Jan 2010
    Posts
    48

    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

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  15. #15
    Member
    Join Date
    Jan 2010
    Posts
    48

    Re: how to kill process immidietly

    Ok I'll fire up a new thread

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    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
  •  



Click Here to Expand Forum to Full Width