Results 1 to 9 of 9

Thread: [RESOLVED] More powerful than API TerminateProcess...

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    53

    Resolved [RESOLVED] More powerful than API TerminateProcess...

    I've tested API TerminateProcess and it did not kill some programs like
    "Warcraft 3 Frozen Throne" as far as i knew the program is not running as
    service...why? is there any other way which is more powerfull to kill a process
    like the one program i mentioned above...thanks

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: More powerful than API TerminateProcess...

    I don't have VB6 with me right now, but stick this in a module and try:
    VB Code:
    1. Option Explicit
    2.  
    3.     Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4.     Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
    5.     (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
    6.     Private Declare Function EnumWindows Lib "user32.dll" _
    7.     (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    8.            
    9.     Private Target As String
    10.     Private Const WM_CLOSE = &H10
    11.  
    12.     Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
    13.         Dim buf As String * 256
    14.         Dim title As String
    15.         Dim length As Long
    16.         Dim hWndREC As Long
    17.         length = GetWindowText(app_hWnd, buf, Len(buf))
    18.         title = Left$(buf, length)
    19.         If InStr(1, title, Target, 3) <> 0 Then
    20.             PostMessage app_hWnd, WM_CLOSE, 0, 0
    21.         End If
    22.         EnumCallback = 1
    23.     End Function
    24.  
    25.     Public Sub CloseProgram(app_name As String)
    26.         Target = app_name
    27.         EnumWindows AddressOf EnumCallback, 0
    28.     End Sub

    Call with
    CloseProgram("Warcraft 3 Frozen Throne"), or whatever the caption is in the toolbar.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    53

    Re: More powerful than API TerminateProcess...

    Works Great thanks...

    but another problem comes up...because i want to programatically kill some processes that way, i dont know how to enumerate the caption of each process that is on the taskbar so that i can pass each caption to closeprogram...can you show me how...thank you very very much.

  4. #4
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: More powerful than API TerminateProcess...

    I'm not sure what you mean.. do you want to end every process with this function?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: More powerful than API TerminateProcess...

    Why do you need to terminate so many processes?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    53

    Re: More powerful than API TerminateProcess...

    Ok, this is what i mean...

    At a certain amount of time, my app should kill some process(a variety of programs) which have been lunch(and was left running) during the session. my app will iterate through a list of that processes and kill each one of them.

    And by using the function above, it needs to know the captions of each processes in order to kill it, right.

    Thats where my problem arise, i have to enumerate and make a list of the "captions" of that variety of running processes, how would i get that "captions" programatically...
    (im pretty sure its not the exe name)

    i hope you understand my explanation...

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: More powerful than API TerminateProcess...

    Umm, no. You can Terminate a running process just by its exe name.

    http://www.vbforums.com/showpost.php...71&postcount=5

    And to enumerate the running processes.

    http://vbforums.com/showthread.php?t=244232
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    New Member
    Join Date
    Nov 2006
    Posts
    4

    Re: More powerful than API TerminateProcess...

    I think i got your problem(same with mine) and maybe This can help you too.

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    53

    Re: More powerful than API TerminateProcess...

    Got it, thanks...

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