Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Media Player Classic Добавлено: 25.01.07 21:44  

Автор вопроса:  Djon | Web-сайт: www.vk-book.ru
Как отслеживать что запущен то или иное проиложение (Media Player Classic)
Спасибо.

Ответить

  Ответы Всего ответов: 2  

Номер ответа: 1
Автор ответа:
 Stars



Вопросов: 41
Ответов: 239
 Профиль | | #1 Добавлено: 25.01.07 22:32
если знаеш путь где он лежит то
Option Explicit

Private Const MAX_PATH As Long = 260&
Private Const MAX_MODULE_NAME32 As Long = 256&
Private Const TH32CS_SNAPPROCESS As Long = &H2
Private Const TH32CS_SNAPMODULE As Long = &H8
Private Const WM_SYSCOMMAND As Long = &H112
Private Const SC_CLOSE As Long = &HF060&

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 Type MODULEENTRY32
  dwSize As Long
  th32ModuleID As Long
  th32ProcessID As Long
  GlblcntUsage As Long
  ProccntUsage As Long
  modBaseAddr As Long
  modBaseSize As Long
  hModule As Long
  szModule As String * MAX_MODULE_NAME32
  szExeFile As String * MAX_PATH
End Type

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
   ByVal hWnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   ByRef lParam As Any) As Long

Private Declare Function Process32First Lib "kernel32.dll" ( _
   ByVal hSnapshot As Long, _
   ByRef lppe As PROCESSENTRY32) As Long

Private Declare Function Process32Next Lib "kernel32.dll" ( _
   ByVal hSnapshot As Long, _
   ByRef lppe As PROCESSENTRY32) As Long

Private Declare Function Module32First Lib "kernel32.dll" ( _
   ByVal hSnapshot As Long, _
   ByRef lpme As MODULEENTRY32) As Long
   
Private Declare Function Module32Next Lib "kernel32.dll" ( _
   ByVal hSnapshot As Long, _
   ByRef lpme As MODULEENTRY32) As Long

Private Declare Function CloseHandle Lib "kernel32.dll" ( _
   ByVal hObject As Long) As Long

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" ( _
   ByVal dwFlags As Long, _
   ByVal th32ProcessID As Long) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32.dll" ( _
   ByVal hWnd As Long, _
   ByRef lpdwProcessID As Long) As Long
   
Private lpdwFoundProcessID As Long
Public Sub iNFO(ByVal sExeForClosing As String)
  Dim lRetval As Long
  lpdwFoundProcessID = GetProcessID(sExeForClosing)
  If lpdwFoundProcessID > 0 Then
    MsgBox "Прога запущена"
  Else
    MsgBox "Прога не запущена"
  End If
End Sub
Private Function GetProcessID(ByVal szExeFile As String) As Long
  Dim lRetvalP As Long
  Dim lRetvalM As Long
  Dim lhSnapshotP As Long
  Dim lhSnapshotM As Long
  Dim lppe As PROCESSENTRY32
  Dim lpme As MODULEENTRY32
  Dim sExeFile As String
  lhSnapshotP = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&;)
  If lhSnapshotP = 0 Then Exit Function
  lppe.dwSize = Len(lppe)
  lRetvalP = Process32First(lhSnapshotP, lppe)
  Do While lRetvalP
    lhSnapshotM = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, lppe.th32ProcessID)
    If lhSnapshotM = 0 Then Exit Function
    lpme.dwSize = Len(lpme)
    lRetvalM = Module32First(lhSnapshotM, lpme)
    Do While lRetvalM
      sExeFile = StringFromBuffer(lpme.szExeFile)
      If LCase(sExeFile) = LCase(szExeFile) Then
        GetProcessID = lpme.th32ProcessID
        GoTo ExitFunction
      End If
      lRetvalM = Module32Next(lhSnapshotM, lpme)
    Loop
    lRetvalP = Process32Next(lhSnapshotP, lppe)
  Loop
ExitFunction:
  lRetvalP = CloseHandle(lhSnapshotP)
  lRetvalM = CloseHandle(lhSnapshotM)
End Function
Public Function StringFromBuffer(ByVal sBuffer As String) As String
  Dim lPos As Integer
  lPos = InStr(sBuffer, vbNullChar)
  If lPos > 0 Then
    StringFromBuffer = Left$(sBuffer, lPos - 1)
  Else
    StringFromBuffer = sBuffer
  End If
End Function



Вызов

iNFO "Путь к файлу"

Ответить

Номер ответа: 2
Автор ответа:
 Stars



Вопросов: 41
Ответов: 239
 Профиль | | #2 Добавлено: 25.01.07 22:47
Или на форму накинь List и сунь код дальше я думаю сам додумаеш пример

Option Explicit
Private Declare Function CreateToolhelp32Snapshot Lib "KERNEL32.dll" ( _
     ByVal dwFlags As Long, _
     ByVal th32ProcessID As Long) As Long
Private Const TH32CS_SNAPMODULE = &H8
Private Const TH32CS_SNAPPROCESS = &H2
Private Const INVALID_HANDLE_VALUE = &HFFFFFFFF

Private Const MAX_MODULE_NAME32 = 255
Private Const MAX_MODULE_NAME32_1 = MAX_MODULE_NAME32 + 1
Private Const MAX_PATH = 260
  
   Private Type PROCESSENTRY32
      dwSize               As Long
      cntUsage             As Long
      th32ProcessID        As Long                              ' This process
      th32DefaultHeapID    As Long 'PTR
      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 * MAX_PATH                 ' Path
   End Type
  
   Private Type MODULEENTRY32
      dwSize               As Long
      th32ModuleID         As Long                              ' This module
      th32ProcessID        As Long                              ' Owning process
      GlblcntUsage         As Long                              ' Global usage count on the module
      ProccntUsage         As Long                              ' Module usage count in th32ProcessID's context
      modBaseAddr          As Byte 'PTR                           ' Base address of module in th32ProcessID's context
      modBaseSize          As Long                              ' Size in bytes of module starting at modBaseAddr
      hModule              As Long                              ' The hModule of this module in th32ProcessID's context
      szModule             As String * MAX_MODULE_NAME32_1
      szExePath            As String * MAX_PATH
   End Type

Private Declare Function Process32First Lib "KERNEL32.dll" ( _
     ByVal hSnapshot As Long, _
     ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "KERNEL32.dll" ( _
     ByVal hSnapshot As Long, _
     ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function Module32First Lib "KERNEL32.dll" ( _
     ByVal hSnapshot As Long, _
     ByRef lpme As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "KERNEL32.dll" ( _
     ByVal hSnapshot As Long, _
     ByRef lpme As MODULEENTRY32) As Long

Private Declare Function CloseHandle Lib "KERNEL32.dll" ( _
     ByVal hObject As Long) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32.dll" ( _
     ByVal hwnd As Long, _
     ByRef lpdwProcessId As Long) As Long

Private Sub Form_Load()
      'Dim MyPID As Long
      'GetWindowThreadProcessId Me.hwnd, MyPID
      
      Dim pe1                        As PROCESSENTRY32
      Dim me1                        As MODULEENTRY32

      Dim hProcessSnap              As Long
      Dim hModuleSnap               As Long
      Dim nModules                  As Long
      Dim nProcesses                As Long
      Dim hProcess                  As Long
      Dim lResult1                  As Long
      Dim lResult2                  As Long
      Dim cb                        As Long
      Dim cbNeeded                  As Long
      Dim i                         As Long
      Dim j                         As Long
 
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&;)
   If hProcessSnap = INVALID_HANDLE_VALUE Then MsgBox "Error", 16, "CreateToolhelp32Snapshot": Exit Sub
   pe1.dwSize = Len(pe1)
   
    lResult1 = Process32First(hProcessSnap, pe1)
   
   
            While lResult1 <> 0
               List1.AddItem pe1.szExeFile
               'If pe1.th32ProcessID = MyPID Then MsgBox pe1.szExeFile, 64

               hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe1.th32ProcessID)
               If hModuleSnap <> INVALID_HANDLE_VALUE Then
                  me1.dwSize = Len(me1)
                  lResult2 = Module32First(hModuleSnap, me1)
                  While lResult2 <> 0
                    If pe1.th32ModuleID <> me1.th32ModuleID Then
                       List1.AddItem "    " & me1.szExePath
                    End If
                       lResult2 = Module32Next(hModuleSnap, me1)
                  Wend
                  CloseHandle hModuleSnap
               End If
               
               lResult1 = Process32Next(hProcessSnap, pe1)
            Wend
            CloseHandle hProcessSnap
End Sub

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам