Visual Basic, .NET, ASP, VBScript
 

   
   
     

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

Страница: 1 |

 

  Вопрос: vb6.0 как узнать жив ли процесс с таким то PID Добавлено: 14.02.06 11:17  

Автор вопроса:  student-uni
есть ли в Visual Basic 6.0 способ чтобы проверить жив ли процесс с известным PID ?

В VB.NET ето GetProcesses
Получаем все процессы
и в цикле смотрим своиства ID и ProcessName каждого
А в вб 6.0 ?

Спасибо

Ответить

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

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



Вопросов: 0
Ответов: 1876


 Профиль | | #1 Добавлено: 14.02.06 11:44
А в VB6 это Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Либо CreateToolhelp32Snapshot для совместимости с 9x.

Ответить

Номер ответа: 2
Автор ответа:
 [root]



Вопросов: 45
Ответов: 1212
 Web-сайт: bit.pirit.info
 Профиль | | #2
Добавлено: 14.02.06 11:57
Вот тут HACKER ложил

МОДУЛЬ ДЛЯ ОБРАБОТКИ ЗАПУЩЕННЫХ ПРОЦЕССОВ В СИСТЕМЕ

http://vbnet.ru/forum/show.aspx?id=97064

Ответить

Номер ответа: 3
Автор ответа:
 student-uni



Вопросов: 122
Ответов: 257
 Профиль | | #3 Добавлено: 14.02.06 13:52
благодарю
тоже нашел



Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
         
Private 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
    
Private Type OSVERSIONINFO
          
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long            '1 = Windows 95.
    szCSDVersion As String * 128    '2 = Windows NT
          
End Type
          
    Const PROCESS_QUERY_INFORMATION = 1024
    Const PROCESS_VM_READ = 16
    Const MAX_PATH = 260
    Const STANDARD_RIGHTS_REQUIRED = &HF0000
    Const SYNCHRONIZE = &H100000                    'STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
    Const PROCESS_ALL_ACCESS = &H1F0FFF
    Const TH32CS_SNAPPROCESS = &H2&
    Const hNull = 0
        
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

Function StrZToStr(s As String) As String
        
    StrZToStr = Left$(s, Len(s) - 1)
        
End Function
        




Private Sub Form_Load()
 List1.Clear

                Select Case getVersion()


                Case 1 'Windows 95/98


                   Dim f As Long, sname As String
                   
                  Dim PID As Variant

                   Dim hSnap As Long
                   Dim proc As PROCESSENTRY32

                   hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)

                   If hSnap = hNull Then Exit Sub

                   proc.dwSize = Len(proc)

                   ' Iterate through the processes

                   f = Process32First(hSnap, proc)

                   Do While f

                     'sname = StrZToStr(proc.szExeFile)
                     'PID = proc.th32ProcessID

                     List1.AddItem sname

                     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_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)

                             List1.AddItem Left(ModuleName, lRet)

                          End If

                      End If

                    'Close the handle To the process

                   lRet = CloseHandle(hProcess)

                   Next



                End Select

End Sub
 

Ответить

Номер ответа: 4
Автор ответа:
 [root]



Вопросов: 45
Ответов: 1212
 Web-сайт: bit.pirit.info
 Профиль | | #4
Добавлено: 14.02.06 20:23
GetWindowThreadProcessId

Ответить

Номер ответа: 5
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #5
Добавлено: 15.02.06 11:30
OpenProcess попробовать по пиду, да и все дела :)

Ответить

Номер ответа: 6
Автор ответа:
 LamerOnLine



ICQ: 334781088 

Вопросов: 108
Ответов: 2822
 Профиль | | #6 Добавлено: 16.02.06 10:59
Есть одна проблема. Если OpenProcess не возвращает хендл - это еще не значит что процесс не существует.

Ответить

Номер ответа: 7
Автор ответа:
 GSerg



Вопросов: 0
Ответов: 1876


 Профиль | | #7 Добавлено: 16.02.06 16:06
Угу... если при этом err.lastdllerror = 5, он таки существует...

Ответить

Номер ответа: 8
Автор ответа:
 PROgrammIST



ICQ: 403099048 

Вопросов: 22
Ответов: 94
 Web-сайт: forum.quotedev.org.ru
 Профиль | | #8
Добавлено: 04.01.10 01:43
Слушайте, а как можно убить нужный процесс?

Ответить

Номер ответа: 9
Автор ответа:
 Smith



ICQ: adamis@list.ru 

Вопросов: 153
Ответов: 3632
 Профиль | | #9 Добавлено: 04.01.10 10:57
Нужные процессы убивать нестоит.
Апи ТерминэйтПроцесс

Ответить

Номер ответа: 10
Автор ответа:
 An



Вопросов: 4
Ответов: 11
 Профиль | | #10 Добавлено: 04.01.10 20:44
Попробуй так

Private Const MAX_PATH = 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 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 Sub Main()
  Call KillProcess("ntvdm.exe";)
End Sub
Private Sub KillProcess(ByVal Proc As String)
    Dim ProcessID As Long, ExeName As String
    Dim hSnapShot As Long, nProcess As Long
    Dim uProcess As PROCESSENTRY32
    Dim hProcess As Long
    
    hSnapShot = CreateToolhelpSnapshot(2, 0)
    uProcess.dwSize = LenB(uProcess)
    nProcess = Process32First(hSnapShot, uProcess)
    
    Do While nProcess
      ExeName = Left(uProcess.szExeFile, InStr(1, uProcess.szExeFile, String(1, 0), vbBinaryCompare) - 1)
        If ExeName = Proc Then
          ProcessID = uProcess.th32ProcessID
          MsgBox "Процесс найден: Exe - " & ExeName & " ; PID: " & CStr(ProcessID) & ";"
          Exit Do
        End If
      nProcess = Process32Next(hSnapShot, uProcess)
     Loop
    CloseHandle hSnapShot
    hProcess = OpenProcess(&H1F0FFF, 1, ProcessID)
    TerminateProcess hProcess, 0
End Sub

Ответить

Страница: 1 |

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



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