Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

In VB Coding - how can I get rid of the processes that still are running in the background?

When I call another program from a VB Code after I close it properly in the VB project (set xx = nothing) the processes are still running in the background. What command line can I write to also kill those processes without having to close the calling program?

2 Answers

Relevance
  • 2 decades ago
    Favorite Answer

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long

    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long

    Private Declare Function GetDesktopWindow Lib "user32" () As Long

    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

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

    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

    Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

    Const GW_HWNDNEXT = 2

    Dim mWnd As Long

    Function InstanceToWnd(ByVal target_pid As Long) As Long

    Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long

    'Find the first window

    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)

    Do While test_hwnd <> 0

    'Check if the window isn't a child

    If GetParent(test_hwnd) = 0 Then

    'Get the window's thread

    test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)

    If test_pid = target_pid Then

    InstanceToWnd = test_hwnd

    Exit Do

    End If

    End If

    'retrieve the next window

    test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)

    Loop

    End Function

    Private Sub Form_Load()

    'KPD-Team 1999

    'URL: http://www.allapi.net/

    'E-Mail: KPDTeam@Allapi.net

    Dim Pid As Long

    'Lock the window update

    LockWindowUpdate GetDesktopWindow

    'Execute notepad.Exe

    Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)

    If Pid = 0 Then MsgBox "Error starting the app"

    'retrieve the handle of the window

    mWnd = InstanceToWnd(Pid)

    'Set the notepad's parent

    SetParent mWnd, Me.hwnd

    'Put the focus on notepad

    Putfocus mWnd

    'Unlock windowupdate

    LockWindowUpdate False

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    'Unload notepad

    DestroyWindow mWnd

    'End this program

    TerminateProcess GetCurrentProcess, 0

    End Sub

    Source(s): Api guide
  • Anonymous
    4 years ago

    do no longer do away with any svchost procedures. maximum of those are necessary gadget procedures. the appropriate thank you to be certain what the procedures are for is to Google them. There are numerous web pages (liutilities is one) that describe the function of the fairly some procedures. yet another place to look is in msconfig.exe you may initiate it from the Run command on the commencing up menu. as quickly because it starts, click on the "Startup" tab. which will tutor you each and all of the courses that are all started up whilst your computing device boots up. returned, use Google to be certain what they do. some would be obtrusive from their call, some no longer. Uncheck any courses which you do no longer desire working interior the historic past. --- replace ---- the certainty that Firefox won't run on your laptop shows that some thing could be heavily incorrect. To log onto the administrator account, sign off of your consumer account (sign off, no longer close down). you may desire to then be supplied with a reveal screen to log in, and between the usernames could desire to be administrator. For a password, enter the two no longer something (merely hit the enter key) or admin or password or passwd. one in all thos eshould artwork.

Still have questions? Get your answers by asking now.