vb如何获取任务管理器中应用程序列表

2025-02-24 21:17:50
推荐回答(3个)
回答1:

  1. Visual Basic是一种由微软公司开发的包含协助开发环境的事件驱动编程语言。

  2. 从任何标准来说,VB都是世界上使用人数最多的语言——不仅是盛赞VB的开发者还是抱怨VB的开发者的数量。

  3. 源自于BASIC编程语言。VB拥有图形用户界面(GUI)和快速应用程序开发(RAD)系统,可以轻易的使用DAO、RDO、ADO连接数据库,或者轻松的创建ActiveX控件。程序员可以轻松的使用VB提供的组件快速建立一个应用程序。

  4. 一个command 一个list。  list中第一个任务管理器,与最后一个Program Manager 过滤不掉 。

  5. 如果想过滤的话 可以在窗体中添加一个判断,来移除。

  6. 这是获取程序

     Process[] ps=Process.GetProcesses();  

    foreach (Process p in ps)  

    {

      if (p.MainWindowHandle != null)

    {  

    richTextBox1.Text += p.MainWindowTitle + "";

     }

     }

  7.  #region 查找所有应用程序标题 private const int GW_HWNDFIRST = 0;

    private const int GW_HWNDNEXT = 2;        

    private const int GWL_STYLE = (-16);        

    private const int WS_VISIBLE = 268435456;        

    private const int WS_BORDER = 8388608;        

    #region AIP声明          

    [DllImport("IpHlpApi.dll")]          

    extern static public uint GetIfTable(byte[] pIfTable, ref uint pdwSize, bool bOrder);        

     [DllImport("User32")]          

    private extern static int GetWindow(int hWnd, int wCmd); 

    [DllImport("User32")]          

    private extern static int GetWindowLongA(int hWnd, int wIndx);

    [DllImport("user32.dll")]          

    private static extern bool GetWindowText(int hWnd, StringBuilder title, int maxBufSize);          

    [DllImport("user32", CharSet = CharSet.Auto)]          

    private extern static int GetWindowTextLength(IntPtr hWnd);        

    #endregion        

    ///

           

    /// 查找所有应用程序标题        

    ///

           

    /// 应用程序标题范型        

    public static List FindAllApps(int Handle)

    {            

     List Apps = new List();            

    int hwCurr;              

    hwCurr = GetWindow(Handle, GW_HWNDFIRST);            

    while (hwCurr > 0)            

    {                  

    int IsTask = (WS_VISIBLE | WS_BORDER);                  

    int lngStyle = GetWindowLongA(hwCurr, GWL_STYLE);                

    bool TaskWindow = ((lngStyle & IsTask) == IsTask);                

    if (TaskWindow)                

    {                      

    int length = GetWindowTextLength(new IntPtr(hwCurr)); 

    StringBuilder sb = new StringBuilder(2 * length + 1);                    

    GetWindowText(hwCurr, sb, sb.Capacity);                    

    string strTitle = sb.ToString();                   

    if (!string.IsNullOrEmpty(strTitle))                    

    {                          

    Apps.Add(strTitle);                    

    }                

    }                  

    hwCurr = GetWindow(hwCurr, GW_HWNDNEXT);            

    return Apps;        

    }          

    #endregion

    调用  

    private void btReApp_Click(object sender, EventArgs e)        

    {              

    LvApp.Items.Clear();              

    List Apps = SystemInfo.FindAllApps((int)this.Handle);            

    foreach (string app in Apps)            

    {                  

    ListViewItem item = new ListViewItem(app);                

    LvApp.Items.Add(item);            

    }        

    }

回答2:

一个command 一个list。 list中第一个 任务管理器,与最后一个Program Manager 过滤不掉
如果你想过滤的话 可以在窗体中添加一个判断,来移除,你懂得
模块代码

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Const GW_OWNER = 4
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim S As String
Dim a As Long
Dim v As Long
S = String(80, 0)
Call GetWindowText(hwnd, S, 80)
S = Left(S, InStr(S, Chr(0)) - 1)

v = GetWindow(hwnd, GW_OWNER)
a = IsWindowVisible(hwnd)
If Len(S) > 0 And a <> 0 And v = 0 Then
Form1.List1.AddItem S
End If
EnumWindowsProc = True
End Function

窗体代码
Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub

回答3:

'你想怎么都行

Option Explicit
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 CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
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 Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Const TH32CS_SNAPPROCESS = &H2&
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 * 260
End Type
Const PROCESS_TERMINATE = 1

Private Sub Form_Load()
Dim lSnapShot As Long, getp0 As String, IDt As String
Dim lNextProcess As Long
Dim tPE As PROCESSENTRY32
lSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If lSnapShot <> -1 Then
tPE.dwSize = Len(tPE)
lNextProcess = Process32First(lSnapShot, tPE)
Do While lNextProcess
getp0 = Left(tPE.szExeFile, InStr(tPE.szExeFile, Chr(0)) - 1)
IDt = IDt & getp0 & vbCrLf
lNextProcess = Process32Next(lSnapShot, tPE)
Loop
CloseHandle (lSnapShot)
End If
MsgBox IDt
Print IDt
End Sub