CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 1999
    Location
    Germany
    Posts
    26

    Process Managment

    Hi,

    is there anybody out there who can help me to manage my Windows-Threads/Processes. I am trying to get a list of ALL running windows processes, which does not seem possible with Windows 98. In Windows NT there is an interface called PSAPI, but I can't seem to get it to work with Win98. Another solution I saw is to get a list of all windows currently active. But this excludes those processes controlled by Windows.

    Does anybody have a solution for me on how to detect all those processes?


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Process Managment

    'module

    Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    Public Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    Public Const TH32CS_SNAPPROCESS = &H2
    Public Const TH32CS_SNAPheaplist = &H1
    Public Const TH32CS_SNAPthread = &H4
    Public Const TH32CS_SNAPmodule = &H8
    Public Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
    Public Const MAX_PATH As Integer = 260

    'define PROCESSENTRY32 structure
    Public 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


    'form (Listview , 2 buttons)

    Private Sub CmdView_Click()
    Dim i As Long
    Dim proc As PROCESSENTRY32
    Dim snap As Long
    Dim exename As String
    lvw.ListItems.Clear 'clear listview contents
    snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) 'get snapshot handle
    proc.dwSize = Len(proc)
    theloop = ProcessFirst(snap, proc) 'first process and return value
    i = 0
    While theloop <> 0 'next process
    exename = proc.szExeFile
    ret = lvw.ListItems.Add(, "first" & CStr(i), exename) 'add process name to listview
    lvw.ListItems("first" & CStr(i)).SubItems(1) = proc.th32ProcessID 'add process ID to listview
    i = i + 1
    theloop = ProcessNext(snap, proc)
    Wend
    CloseHandle snap 'close snapshot handle
    End Sub
    Private Sub CmdEnd_Click()
    Dim i As Long
    hand = OpenProcess(process_terminate, True, CLng(lvw.SelectedItem.SubItems(1))) 'get process handle
    TerminateProcess hand, 0 'end define process
    Call CmdView_Click
    End Sub

    Private Sub Form_Load()
    Dim header As ColumnHeader
    lvw.View = lvwReport
    lvw.ColumnHeaders.Clear
    Set header = lvw.ColumnHeaders.Add(, "first", "Process", 4200) 'set listview width
    Set header = lvw.ColumnHeaders.Add(, "second", "ID", 1200)
    lvw.Refresh
    End Sub



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Oct 2000
    Location
    Moncton NB, Canada
    Posts
    49

    Re: Process Managment

    Iouri,

    I came across this code and implemented it into a program of mine, When I ran it on windows 2000 Professional with package and deploy it ran, but when I ran it on NT 4.0 with Package and Deploy it gave me an error "can't create dll entry point Createtoolhelp32snaphot in Kernel 32"

    Have you run across this problem before?

    Could you send me a message if you know the answer

    PS - I'm running VB 6 with SP3

    Thanks

    DJ


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Process Managment

    I am running VB6 SP4 on Win98. I never tried it on NT. Probably it is different API, but I am not familiar with NT

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Jun 2005
    Location
    gandhinagar,gujarat
    Posts
    51

    Re: Process Managment

    above code gives error like below

    code portion............
    Private Sub Form_Load()
    Dim header As ColumnHeader


    error......."user-deifined type not defined"


    other doutful' code section is as under............

    nap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) 'get snapshot handle
    proc.dwSize = Len(proc)
    theloop = ProcessFirst(snap, proc) 'first process and return value
    i = 0
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''possible errror section
    While the loop <> 0 'next process
    .....;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;possible error section
    exename = proc.szExeFile
    ret = lvw.ListItems.Add(, "first" & CStr(i), exename) 'add process name to listview
    lvw.ListItems("first" & CStr(i)).Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured