Announcement

Collapse
No announcement yet.

List all process in pb/win

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    want to convert code from C/C++ to Pb/win for List All a Process.
    Why convert the 'c' code?

    Do a search here on the word 'process,' forum source code, message subject, any date.

    MCM

    Leave a comment:


  • Tom Hanlin
    replied
    "Jack", bubby, real name, please-- just like you agreed when you
    registered. Thank you.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Kev Peel
    replied
    Hmm, I wondered where the TYPE and FUNCTION definitions were. They're in "TLHELP32.INC"

    ------------------
    Kev Peel
    http://www.kgpsoftware.com

    Leave a comment:


  • Kev Peel
    replied
    Almost direct translation (note that I've used MsgBox instead of Print)...

    Code:
     
    #Include "WIN32API.INC"
     
    %TH32CS_SNAPHEAPLIST    = &H1
    %TH32CS_SNAPPROCESS     = &H2
    %TH32CS_SNAPTHREAD      = &H4
    %TH32CS_SNAPMODULE      = &H8
    %TH32CS_SNAPALL         = (%TH32CS_SNAPHEAPLIST Or %TH32CS_SNAPPROCESS Or %TH32CS_SNAPTHREAD Or %TH32CS_SNAPMODULE)
    %TH32CS_INHERIT         = &H80000000
     
    Type PROCESSENTRY32
         dwSize As Dword
         cntUsage As Dword
         th32ProcessID As Dword
         th32DefaultHeapID As Dword
         th32ModuleID As Dword
         cntThreads As Dword
         th32ParentProcessID As Dword
         pcPriClassBase As Long
         dwFlags As Dword
         szExeFile As Asciiz * %MAX_PATH
    End Type
     
    Declare Function CreateToolhelp32Snapshot Lib "KERNEL32.DLL" Alias "CreateToolhelp32Snapshot" (ByVal dwFlags As Dword, ByVal th32ProcessID As Dword) As Dword
    Declare Function Process32First Lib "KERNEL32.DLL" Alias "Process32First" (ByVal hSnapshot As Dword, ByRef lppe As PROCESSENTRY32) As Long
    Declare Function Process32Next Lib "KERNEL32.DLL" Alias "Process32Next" (ByVal hSnapshot As Dword, ByRef lppe As PROCESSENTRY32) As Long
     
      
    Function PBMain
       Local pe32 As PROCESSENTRY32, hProcessSnap As Dword, rProcessFound As Long, sText As String
     
       hProcessSnap = CreateToolhelp32Snapshot(%TH32CS_SNAPPROCESS, 0)
       If (hProcessSnap = %INVALID_HANDLE_VALUE) Then
          Function = 1
          Exit Function
       End If
        
       pe32.dwSize = SizeOf(pe32)
       rProcessFound = Process32First(hProcessSnap, pe32)
     
       Do While (rProcessFound = %True)
            sText = sText + "ID: " + Format$(pe32.th32ProcessID) + $Tab + "File: " + pe32.szExeFile + $CrLf
            rProcessFound = Process32Next(hProcessSnap, pe32)
       Loop
            
       If Len(sText) Then MsgBox sText, %MB_ICONINFORMATION, "Process List"
     
       CloseHandle hProcessSnap
    End Function

    Ps. Needs Win95/98/ME or NT5+ according to MSDN.



    ------------------
    Kev Peel
    http://www.kgpsoftware.com

    Leave a comment:


  • Guest's Avatar
    Guest started a topic List all process in pb/win

    List all process in pb/win

    Dear programmer
    I want to convert code from C/C++ to Pb/win for List All a Process.
    This is my source code.
    ################### List All Process ########
    PROCESSENTRY32 pe32;
    HANDLE hProcessSnap;
    BOOL rProcessFound;

    hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hProcessSnap == INVALID_HANDLE_VALUE){
    exit(1);
    }
    pe32.dwSize=sizeof(pe32);
    rProcessFound=Process32First(hProcessSnap,&pe32);

    do {
    printf("%*s", 25, pe32.szExeFile);
    printf( "\t\t%*d\n", 4, pe32.th32ProcessID);
    }while ( rProcessFound=Process32Next(hProcessSnap,&pe32) );
    CloseHandle(hProcessSnap);
    ######################################

    How to a coding in pb/win?
    Thank you verymuch.


    ------------------
Working...
X