Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    57

    [VB6] Intercettare gli eseguibili

    salve a tutti,
    avrei bisogno di fare un programma in vb6 che sia sempre attivo in background.
    questo programma mi deve dire, ogni volta che un eseguibile viene aperto, il nome dell'applicazione attivata.
    come posso fare?
    grazie

  2. #2
    Ciao..
    1) lo fai partire all'avvio di Windows
    2) puoi mettere un timer ed enumerare i processi attivi in una listbox (oppure salvarli in un file..)
    Oppure:
    Attiva un Hook di sistema, ma farlo con visual basic è sconsigliato, se sai un pò di C fai con quello..

    ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    57
    scusa ma devi fare qualche passo indietro
    cos'è un hook?
    puoi spiegarmi meglio il punto due?
    il background non è un problema.

    grazie

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    57
    c'è un api che mi fornisce la lista dei processi attivi?
    come si chiama?

  5. #5
    Ti posso postare direttamente il codice, poi ci pensi autonomamente a studiarlo e chiaramente, se non capisci qualcosa, te lo dirò..
    In un modulo:
    codice:
     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
             th32DefaultHeapID As Long
             th32ModuleID As Long
             cntThreads As Long
             th32ParentProcessID As Long
             pcPriClassBase As Long
             dwFlags As Long
             szExeFile As String * 260
          End Type
    
          Public Type OSVERSIONINFO
             dwOSVersionInfoSize As Long
             dwMajorVersion As Long
             dwMinorVersion As Long
             dwBuildNumber As Long
             dwPlatformId As Long
                                            
    
             szCSDVersion As String * 128
          End Type
    
          Public Const PROCESS_QUERY_INFORMATION = 1024
          Public Const PROCESS_VM_READ = 16
          Public Const MAX_PATH = 260
          Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
          Public Const SYNCHRONIZE = &H100000
          
          Public Const PROCESS_ALL_ACCESS = &H1F0FFF
          Public Const TH32CS_SNAPPROCESS = &H2&
          Public Const hNull = 0
    
          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
    In un form con una listbox:
    codice:
    List1.Clear
          
          Select Case getVersion()
          
          Case 1
    
             Dim f As Long
             Dim sname As String
             Dim hSnap As Long
             Dim proc As PROCESSENTRY32
             hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
             If hSnap = hNull Then Exit Sub
             proc.dwSize = Len(proc)
             
             f = Process32First(hSnap, proc)
             Do While f
               sname = StrZToStr(proc.szExeFile)
               List1.AddItem sname
               f = Process32Next(hSnap, proc)
             Loop
    
          Case 2
             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
             
             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
                
                hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _
                   Or PROCESS_VM_READ, 0, ProcessIDs(i))
                
                If hProcess <> 0 Then
                    
                    lRet = EnumProcessModules(hProcess, Modules(1), 200, _
                                                 cbNeeded2)
                    
                    If lRet <> 0 Then
                       ModuleName = Space(MAX_PATH)
                       nSize = 500
                       lRet = GetModuleFileNameExA(hProcess, Modules(1), _
                                       ModuleName, nSize)
                       List1.AddItem Left(ModuleName, lRet)
                    End If
                End If
              
             lRet = CloseHandle(hProcess)
             Next
    
          End Select
    Tutto questo magari associato ad un Timer.
    Per correttezza ti dico che questo esempio lo avevo nel computer e non l'ho scritto io.

    Ciao

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 © 2025 vBulletin Solutions, Inc. All rights reserved.