Как закрыть другую программу из своего приложения?
Есть пример, но там устаревшая функции GetWindowTask. http://www.microsoft.com/Rus/Msdn/Activ/MSVB/Archive/Interaction/15.mspx. На что изменить?
Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal _
lpWindowName As Any) As Integer
Declare Function GetWindowTask Lib "User" (ByVal hWnd As Integer) As Integer
Declare Function PostAppMessage Lib "User" (ByVal hTask As Integer, ByVal
wMsg _
As Integer, ByVal wParam As Integer, lParam As Any) As Integerм
Title = "Программа А"
ihWnd = FindWindow(0&, Title)
ihTask = GetWindowTask(ihWnd)
iRet = PostAppMessage(ihTask, WM_QUIT, 0, 0&)
MsgBox "Внимание! Программа А закрывается"
Public Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
Public Declare Function PostThreadMessage Lib "user32.dll" Alias "PostThreadMessageA" (ByVal idThread As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
ihWnd = FindWindow("Notepad", "Безымянный - Блокнот")
ihTask = GetWindowThreadProcessId(ihWnd, 0)
iRet = PostThreadMessage(ihTask, WM_QUIT, 0, 0&)
MsgBox "Внимание! Программа Notepad закрывается"
Хакер писал(а):И ByRef lpdwProcessId As Long замени на Byval lpdwProcessId as long и передавай 0& соотвественно.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Sub Command1_Click()
Dim hwnd As Long
Dim pid As Long
Dim hproc As Long
Dim ecode As Long
hwnd = FindWindow("SciCalc", vbNullString)
If Not hwnd = 0 Then
GetWindowThreadProcessId hwnd, pid
hproc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)
GetExitCodeProcess hproc, ecode
TerminateProcess hproc, ecode
CloseHandle hproc
Else
MsgBox "Window not found!", vbExclamation
End If
End Sub
Сейчас этот форум просматривают: Google-бот, Yandex-бот и гости: 60