Home > Software engineering >  How to normal end of a process, not to kill, okay
How to normal end of a process, not to kill, okay

Time:10-14

VB how to turn off a normal process, process name, known as java_1. Exe

CodePudding user response:

Call API

CodePudding user response:

How to call, is a service, the service startup called JAVA1. Exe (Java. Exe a copy), when I service close to install JAVA1. Exe also turn off, but JAVA1. Exe no window, how about API messages?

CodePudding user response:

Use TerminateProcess?
 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
The Function InstanceToWnd (ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'the Find the first window
Test_hwnd=FindWindow (ByVal 0 & amp; , ByVal 0 & amp;)
The Do While test_hwnd & lt;> 0
'to Check if the window isn' t a child
Then If GetParent (test_hwnd)=0
'Get the window' s thread
Test_thread_id=GetWindowThreadProcessId (test_hwnd test_pid)
If test_pid=target_pid Then
InstanceToWnd=test_hwnd
The Exit Do
End the If
End the If
'retrieve the next window
Test_hwnd=GetWindow (test_hwnd GW_HWNDNEXT)
Loop
End the Function
Private Sub Form_Load ()
'KPD - Team 1999
'the URL: http://www.allapi.net/
'E - Mail: [email protected]
Dim Pid As Long
'Lock the Windows update
LockWindowUpdate GetDesktopWindow
'the 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)
'the Unload notepad
DestroyWindow mWnd
'End this program
The TerminateProcess GetCurrentProcess, 0
End Sub

CodePudding user response:

Don't try to the end of the elegant (because it is impossible)
And want to be in bad can't lousy can stall on reforming land!
  •  Tags:  
  • API
  • Related