VBCoding Библиотека кодов Visual Basic 6 Оболочка и система Получить список запущенных процессов

Visual Basic 6
Получить список запущенных процессов

Расположите на форме 2 элемента CommandButton и элемент ListBox.

ВАЖНОЕ ПРИМЕЧАНИЕ: БУДЬТЕ АККУРАТНЫ ПРИ ИСПОЛЬЗОВАНИИ ЭТОГО ПРИМЕРА


Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) 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
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const WM_CLOSE = &H10
Const WM_QUIT = &H12
Dim CurrWnd As String
Dim ListItem As String
Dim Length As String

Sub GetTaskList()
CurrWnd = GetWindow(Me.hwnd, GW_HWNDFIRST)
Do While CurrWnd <> 0
Length = GetWindowTextLength(CurrWnd)
ListItem = Space(Length + 1)
Length = GetWindowText(CurrWnd, ListItem, Length + 1)
If Length <> 0 Then
List1.AddItem ListItem
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Loop
End Sub

Private Sub Command1_Click()
List1.Clear
GetTaskList
End Sub

Private Sub Command2_Click()
hW = FindWindow(vbNullString, List1.Text & Chr(0))
PostMessage hW, WM_QUIT, 0, 0
End Sub

Private Sub Form_Load()
Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2
GetTaskList
Command1.Caption = "получить список"
Command2.Caption = "Закрыть приложение"
End Sub

 

Источник: http://www.vbnet.ru/ 

 

Добавить комментарий


Защитный код
Обновить

 
VBCoding Библиотека кодов Visual Basic 6 Оболочка и система Получить список запущенных процессов  
Powered by Exponenta -