Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    [C++ o Dos]Come terminare un processo

    Quale comando posso utilizzare in C++ o in dos per terminare un processo? Per esempio per terminare explorer?

    Grazie.

  2. #2
    puoi usare l'api

    TerminateProcess

    ma ti serve il processID del processo

  3. #3
    Scusa potresti spiegarmi meglio? Magari facendomi un esempio di codice, Thz

    Volendo posso anche lanciare l'applicazione Task Manager ma la cosa deve essere fatta tutta in automatico

  4. #4
    ho un esempio in vb che chima le api
    codice:
    Private Const TH32CS_SNAPPROCESS As Long = 2&
    Private Const MAX_PATH As Long = 260
    
    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 * MAX_PATH
    End Type
    
    Private Declare Sub CloseHandle Lib "Kernel32.dll" (ByVal hPass As Long)
    Private Declare Function CreateToolhelpSnapshot Lib "Kernel32.dll" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    Private Declare Function ProcessFirst Lib "Kernel32.dll" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    Private Declare Function ProcessNext Lib "Kernel32.dll" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    
    Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Declare Function PostMessage Lib "User32" Alias "PostMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function IsWindow Lib "User32" (ByVal Hwnd As Long) As Long
    Private Declare Function GetWindow Lib "User32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetWindowLong Lib "User" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
    Const GW_OWNER = 4
    Const GWL_STYLE = -16
    Const WS_DISABLED = &H8000000
    Const WS_CANCELMODE = &H1F
    Const WM_CLOSE = &H10
    
    Private Function ProcessoAttivo(NomeProcesso As String) As Boolean
    Dim uProcess As PROCESSENTRY32
    Dim continua As Long
    Dim Verifica As String
    Dim hSnapShot
    hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    If hSnapShot = 0 Then Exit Function
    uProcess.dwSize = Len(uProcess)
    continua = ProcessFirst(hSnapShot, uProcess)
    ProcessoAttivo = False
    Do While continua
        continua = ProcessNext(hSnapShot, uProcess)
        Verifica = uProcess.szExeFile
        If Trim(Verifica) <> "" Then
            If InStr(1, LCase(Left(Verifica, InStr(1, Verifica, Chr(0)) - 1)), LCase(NomeProcesso)) <> 0 Then ProcessoAttivo = True: Exit Function
        End If
    Loop
    Call CloseHandle(hSnapShot)
    
    End Function
    
    
    Public Sub tiraGiu(par)
    Dim winHwnd As Long
    winHwnd = FindWindow(vbNullString, CStr(par))
    If winHwnd <> 0 Then
        PostMessage winHwnd, WS_CANCELMODE, 0, 0&
        PostMessage winHwnd, WM_CLOSE, 0, 0&
    End If
    end sub
    
    If ProcessoAttivo("Nome Processo") = True Then
       tiraGiu "Nome Processo"
    End If
    ho solo questo, chon non usa un TerminateProcess, ma invia un msg di chuisura alla finenste
    Per avere il processId forse lo trovi dentro alla struttura PROCESSENTRY32, quindi la varibile uProcess di ProcessoAttivo.
    Con questo puoi usare il termitateProcess
    Però non so come fai a distinguere ad esempio tra le diverse istanze di IE

  5. #5
    Qualcosa di un pò più semplice?

  6. #6
    Nessuno conosce un modo più semplice allora?

  7. #7
    ...Terrible warlords, good warlords, and an english song

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.