Страница: 1 |
Вопрос: Закрыть программу
Добавлено: 09.05.09 08:45
Автор вопроса: $@ny@PG | ICQ: 468469477
Как в vb 6.0 можно закрыть чужое окно или программу?
Ответить
Номер ответа: 3Автор ответа: AWP
ICQ: 345685652 Вопросов: 96Ответов: 1212
Web-сайт: xawp.narod.ru Профиль | | #3
Добавлено: 09.05.09 15:23
Код модуля:
Option Explicit
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 260
End Type
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long , ByVal bInheritHandle As Long , ByVal dwProcessId As Long ) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long , ByVal uExitCode As Long ) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long , ByVal lProcessID As Long ) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long , uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long , uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long )
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" _
Alias "LookupPrivilegeValueA" ( _
ByVal lpSystemName As String , _
ByVal lpName As String , _
lpLuid As LUID) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" ( _
ByVal ProcessHandle As Long , _
ByVal DesiredAccess As Long , _
ByRef TokenHandle As Long ) As Long
Private Declare Function GetLastError Lib "kernel32.dll" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32.dll" () As Long
Private Const MAX_PATH As Long = 260
Private Const SE_DEBUG_NAME As String = "SeDebugPrivilege"
Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20
Private Const TOKEN_QUERY As Long = &H8
Private Const SE_PRIVILEGE_ENABLED As Long = &H2
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" ( _
ByVal TokenHandle As Long , _
ByVal DisableAllPrivileges As Long , _
ByRef NewState As TOKEN_PRIVILEGES, _
ByVal BufferLength As Long , _
ByRef PreviousState As TOKEN_PRIVILEGES, _
ByRef ReturnLength As Long ) As Long
Dim tm As Variant
Public CanISend As Long
Function LoadPrivilege(ByVal Privilege As String ) As Boolean
Dim hToken As Long
Dim SEDebugNameValue As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim hProcessHandle As Long
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lbuffer As Long
hProcessHandle = GetCurrentProcess()
OpenProcessToken hProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hToken
LookupPrivilegeValue "" , Privilege, SEDebugNameValue
With tkp
.PrivilegeCount = 1
.TheLuid = SEDebugNameValue
.Attributes = SE_PRIVILEGE_ENABLED
End With
AdjustTokenPrivileges hToken, False , tkp, Len(tkp), tkpNewButIgnored, lbuffer
LoadPrivilege = True
End Function
Sub KillProcs(PID As Long )
Dim hProcess As Long
On Error GoTo 3
hProcess = OpenProcess(&H1F0FFF, 1, PID)
TerminateProcess hProcess, 0
Exit Sub
3
End Sub
Sub KillProcesse(pName As String )
Dim hSnapShot As Long , nProcess As Long
Dim uProcess As PROCESSENTRY32
Dim hProcess As Long
Dim LG As Long
LG = Len(pName)
hSnapShot = CreateToolhelpSnapshot(2, 0)
uProcess.dwSize = LenB(uProcess)
nProcess = Process32First(hSnapShot, uProcess)
On Error GoTo 20
Do While nProcess
If LCase(Mid$(uProcess.szExeFile, 1, LG)) = LCase(pName) Then
hProcess = OpenProcess(&H1F0FFF, 1, uProcess.th32ProcessID)
TerminateProcess hProcess, 0
GoTo 10
End If
nProcess = Process32Next(hSnapShot, uProcess)
Loop
10
CloseHandle hSnapShot
Exit Sub
20
End Sub
Ответить
Номер ответа: 6Автор ответа: Smith
ICQ: adamis@list.ru Вопросов: 153Ответов: 3632
Профиль | | #6
Добавлено: 09.05.09 16:01
Фигасе модули у вас, а больше не нашлось?
Не издевайте пожалуйсто мой моск, его и так мала
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String , ByVal lpWindowName As String ) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long , lpdwProcessId 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 TerminateProcess Lib "kernel32" (ByVal hProcess As Long , ByVal uExitCode As Long ) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long , ByVal lpOperation As String , ByVal lpFile As String , ByVal lpParameters As String , ByVal lpDirectory As String , ByVal nShowCmd As Long ) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long ) As Long
Sub Main()
Dim pID As Long
Dim tmpL As Long
tmpL = FindWindow(vbNullString, "Это имя окна программы!!!!!!!!!!!!!!" & vbNullChar)
GetWindowThreadProcessId tmpL, pID
tmpL = OpenProcess(1, False , pID)
TerminateProcess tmpL, 0
CloseHandle tmpL
End Sub
Ответить
Номер ответа: 7Автор ответа: AWP
ICQ: 345685652 Вопросов: 96Ответов: 1212
Web-сайт: xawp.narod.ru Профиль | | #7
Добавлено: 09.05.09 16:13
Фигасе модули у вас, а больше не нашлось?
Вы сейчас закрыли программу по окну, а в модуле можно закрыть по окну, по имени процесса, по PID, по пути файла и т.д...
Ответить
Страница: 1 |
Поиск по форуму