Этот баннер — требование Роскомнадзора для исполнения 152 ФЗ.
«На сайте осуществляется обработка файлов cookie, необходимых для работы сайта, а также для анализа использования сайта и улучшения предоставляемых сервисов с использованием метрической программы Яндекс.Метрика. Продолжая использовать сайт, вы даёте согласие с использованием данных технологий».
Политика конфиденциальности
|
|
|
TerminateProcess
|
|||
|---|---|---|---|
|
#18+
Не срабатывает функция TerminateProcess (WinXP,Win2000) Есть идеи? 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 ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) Private Sub Form_Load() Dim Pid&, di& Pid& = FindWindow(vbNullString, "Project1") If Pid& <> 0 Then di& = TerminateProcess(Pid&, 0&) End Sub 'находим id процесса Function FindProc(strPrilName As String) As Long Dim hSnapShot As Long Dim uProcess As PROCESSENTRY32 Dim r As Long hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) If hSnapShot = 0 Then Exit Function End If uProcess.dwSize = Len(uProcess) r = ProcessFirst(hSnapShot, uProcess) Do While r If InStr(1, uProcess.szExeFile, strPrilName) Then FindProc = uProcess.th32ProcessID Call CloseHandle(hSnapShot) Exit Function End If r = ProcessNext(hSnapShot, uProcess) Loop Call CloseHandle(hSnapShot) End Function ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 17.02.2004, 16:22 |
|
||
|
TerminateProcess
|
|||
|---|---|---|---|
|
#18+
Попробуй так: TerminateProcess(byval Pid&, 0&) Magnus ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 17.02.2004, 16:37 |
|
||
|
TerminateProcess
|
|||
|---|---|---|---|
|
#18+
Нет, не помогает, не хочет он прерываться ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 17.02.2004, 16:44 |
|
||
|
TerminateProcess
|
|||
|---|---|---|---|
|
#18+
пробелма в том что ты ему передаешь ProcID а нужен хендл. Щас.. Magnus ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 17.02.2004, 17:08 |
|
||
|
TerminateProcess
|
|||
|---|---|---|---|
|
#18+
Немного мутно, но если что спрашивай. с NT больше проблем с правами на завершение процесса. Это в модуль: Option Explicit Public Declare Function TerminateProcess Lib "kernel32" ( _ ByVal hProcess As Long, ByVal uExitCode As Long) As Long Public Declare Function Process32First Lib "kernel32" ( _ ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Public Declare Function Process32Next Lib "kernel32" ( _ ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Public Declare Function CloseHandle Lib "Kernel32.dll" _ (ByVal Handle As Long) As Long Public Declare Function OpenProcess Lib "Kernel32.dll" _ (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _ ByVal dwProcId As Long) As Long Public Declare Function EnumProcesses Lib "psapi.dll" _ (ByRef lpidProcess As Long, ByVal cb As Long, _ ByRef cbNeeded As Long) As Long Public Declare Function GetModuleFileNameExA Lib "psapi.dll" _ (ByVal hProcess As Long, ByVal hModule As Long, _ ByVal ModuleName As String, ByVal nSize As Long) As Long Public Declare Function EnumProcessModules Lib "psapi.dll" _ (ByVal hProcess As Long, ByRef lphModule As Long, _ ByVal cb As Long, ByRef cbNeeded As Long) As Long Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" ( _ ByVal dwflags As Long, ByVal th32ProcessID As Long) As Long Public Declare Function GetVersionExA Lib "kernel32" _ (lpVersionInformation As OSVERSIONINFO) As Integer Public Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long ' This process th32DefaultHeapID As Long th32ModuleID As Long ' Associated exe cntThreads As Long th32ParentProcessID As Long ' This process's parent process pcPriClassBase As Long ' Base priority of process threads dwflags As Long szExeFile As String * 260 ' MAX_PATH End Type Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long '1 = Windows 95 2 = Windows NT szCSDVersion As String * 128 End Type Public Const PROCESS_TERMINATE = &H1 Public Const PROCESS_QUERY_INFORMATION = 1024 Public Const PROCESS_VM_READ = 16 Public Const MAX_PATH = 260 Public Const TH32CS_SNAPPROCESS = &H2& Public Const hNull = 0 Public Function StrZToStr(s As String) As String StrZToStr = Left$(s, Len(s) - 1) End Function Public Function getVersion() As Long Dim osinfo As OSVERSIONINFO Dim retvalue As Integer osinfo.dwOSVersionInfoSize = 148 osinfo.szCSDVersion = Space$(128) retvalue = GetVersionExA(osinfo) getVersion = osinfo.dwPlatformId End Function Public Function KillAppByEXEName(NameOfEXE As String) As Boolean NameOfEXE = UCase(NameOfEXE) KillAppByEXEName = False ' Assume the worst Select Case getVersion() Case 1 'Windows 95/98 Dim f As Long, sname As String Dim hSnap As Long, Proc As PROCESSENTRY32 Dim ProcFromprocid As Long hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) If hSnap = hNull Then Exit Function End If Proc.dwSize = Len(Proc) ' Iterate through the processes f = Process32First(hSnap, Proc) Do While f sname = StrZToStr(Proc.szExeFile) sname = UCase(Trim(sname)) If InStr(sname, NameOfEXE) > 0 Then ProcFromprocid = OpenProcess(PROCESS_QUERY_INFORMATION Or _ PROCESS_VM_READ, 0, Proc.th32ProcessID) ' get Call TerminateProcess(ProcFromprocid, 0) KillAppByEXEName = True Exit Function End If f = Process32Next(hSnap, Proc) Loop Case 2 'Windows NT Dim cb As Long Dim cbNeeded As Long Dim NumElements As Long Dim ProcessIDs() As Long Dim cbNeeded2 As Long Dim NumElements2 As Long Dim Modules(1 To 200) As Long Dim lRet As Long Dim ModuleName As String Dim nSize As Long Dim hProcess As Long Dim i As Long 'Get the array containing the process id's for each process object cb = 8 cbNeeded = 96 Do While cb <= cbNeeded cb = cb * 2 ReDim ProcessIDs(cb / 4) As Long lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded) Loop NumElements = cbNeeded / 4 For i = 1 To NumElements 'Get a handle to the Process hProcess = OpenProcess(PROCESS_TERMINATE Or PROCESS_QUERY_INFORMATION _ Or PROCESS_VM_READ, 0, ProcessIDs(i)) 'Got a Process handle If hProcess <> 0 Then 'Get an array of the module handles for the specified 'process lRet = EnumProcessModules(hProcess, Modules(1), 200, _ cbNeeded2) 'If the Module Array is retrieved, Get the ModuleFileName If lRet <> 0 Then ModuleName = Space(MAX_PATH) nSize = 500 lRet = GetModuleFileNameExA(hProcess, Modules(1), _ ModuleName, nSize) ModuleName = UCase(Trim(ModuleName)) If InStr(ModuleName, NameOfEXE) > 0 Then Call TerminateProcess(hProcess, 0) KillAppByEXEName = True Exit Function End If End If End If 'Close the handle to the process lRet = CloseHandle(hProcess) Next End Select End Function А этим килять KillAppByEXEName("Project1.exe") Magnus ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 17.02.2004, 19:14 |
|
||
|
TerminateProcess
|
|||
|---|---|---|---|
|
#18+
Огромное спасибо за помощь и отдельное спасибо за развернутый ответ(все понятно) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 18.02.2004, 16:22 |
|
||
|
|

start [/forum/topic.php?fid=60&msg=32412362&tid=2170060]: |
0ms |
get settings: |
11ms |
get forum list: |
19ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
41ms |
get topic data: |
9ms |
get forum data: |
2ms |
get page messages: |
47ms |
get tp. blocked users: |
1ms |
| others: | 236ms |
| total: | 374ms |

| 0 / 0 |
