none
VB获取进程列表 RRS feed

  • 问题

  • Option Explicit
    Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    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 * 512
    End Type
      Const TH32CS_SNAPheaplist = &H1
      Const TH32CS_SNAPPROCESS = &H2
      Const TH32CS_SNAPthread = &H4
      Const TH32CS_SNAPmodule = &H8
      Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
    Public Function Getprocess() As String
    Dim Proc      As PROCESSENTRY32
    Dim hSnapShot As Long
    Dim lpid      As Long
    hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPall, 0)
    Proc.dwSize = Len(Proc)
    lpid = ProcessFirst(hSnapShot, Proc)
    Do While lpid <> 0
    Getprocess = Getprocess + Proc.szExeFile + Chr(13)
    lpid = ProcessNext(hSnapShot, Proc)
    Loop
     CloseHandle hSnapShot
    End Function


    为什么调用Getprocess的返回值只有[System Process]
    2009年7月15日 10:26

答案