Results 1 to 4 of 4

Thread: How can i kill a background process !

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    9

    Smile How can i kill a background process !

    hi,
    can anyone tell me how i can kill a background process in VB running in wondows ? process like apache server, sql server or any other unwanted process that i dont need at the moment ?

    if possible please tell me which functions to use or which reference to be added ? code snipets are welcome as well.

  2. #2
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Re: How can i kill a background process !

    try this code
    VB Code:
    1. 'Module Declaration
    2.  
    3. Option Explicit
    4.  
    5. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    6. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    7. Public Const WM_CLOSE = &H10
    8.  
    9.  
    10. 'Code
    11.  
    12. Public Sub CloseProgram(ByVal Caption as String)
    13.  
    14.  Dim Handle As Long
    15.  
    16.  Handle= FindWindow(vbNullString, Caption)
    17.  If Handle = 0 Then Exit Sub
    18.  SendMessage Handle, WM_CLOSE, 0&, 0&
    19.  
    20. End Sub
    21.  
    22.  
    23. 'BUTTON
    24.  
    25. Private Sub Command1_Click()
    26.  
    27.     CloseProgram ("Title/Name of the Application")
    28.  
    29. End Sub
    noister
    <advertising link removed by moderator>

  3. #3
    Addicted Member
    Join Date
    Apr 2006
    Location
    Sweden
    Posts
    173

    Re: How can i kill a background process !

    cool code!

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

    Re: How can i kill a background process !

    That will work for processes with a visible window and/or window caption. To truely close a program you need to Terminate its process. Search the forums for Terminate Process and you will find many examples already, a couple by me too.
    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

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