home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD152552202001.psc / modTasks.bas < prev   
Encoding:
BASIC Source File  |  2001-02-21  |  6.5 KB  |  100 lines

  1. Attribute VB_Name = "modTasks"
  2. Option Explicit
  3. '==========================================================================================================='
  4. ' Constant Declarations                                                                                     '
  5. '==========================================================================================================='
  6. Global Const PROCESS_PRIORITY_IDLE = 4
  7. Global Const PROCESS_PRIORITY_NORMAL = 8
  8. Global Const PROCESS_PRIORITY_HIGH = 13
  9. Global Const PROCESS_PRIORITY_REALTIME = 24
  10. ' Priority type, when setting with SetPriorityClass
  11. Private Const HIGH_PRIORITY_CLASS = &H80                    ' Hogs CPU over idle and normal classes
  12. Private Const IDLE_PRIORITY_CLASS = &H40                    ' Only runs when the CPU is idle
  13. Private Const NORMAL_PRIORITY_CLASS = &H20                  ' Duh!
  14. Private Const REALTIME_PRIORITY_CLASS = &H100               ' Highest priority. Even pre-empts operating system
  15.                                                             ' processes, so use with discretion
  16. ' Access description when opening a handle to a process.
  17. ' These codes aren't in the API viewer, had to get them at Microsoft's site.
  18. Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
  19. Public Const SYNCHRONIZE = &H100000
  20. Public Const PROCESS_TERMINATE = &H1&                       ' Used to kill a process
  21. Public Const PROCESS_CREATE_THREAD = &H2&
  22. Public Const PROCESS_VM_OPERATION = &H8&
  23. Public Const PROCESS_VM_READ = &H10&
  24. Public Const PROCESS_VM_WRITE = &H206
  25. Public Const PROCESS_DUP_HANDLE = &H40&
  26. Public Const PROCESS_CREATE_PROCESS = &H80&
  27. Public Const PROCESS_SET_QUOTA = &H100&
  28. Public Const PROCESS_SET_INFORMATION = &H200&               ' Used to set information on a process (like priority)
  29. Public Const PROCESS_QUERY_INFORMATION = &H400&
  30. Public Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
  31. '==========================================================================================================='
  32. ' API Declarations                                                                                          '
  33. '==========================================================================================================='
  34. ' Used to return process information                                                                        '
  35. '-----------------------------------------------------------------------------------------------------------'
  36. Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal dwIdProc As Long) As Long
  37. Declare Function Process32First Lib "kernel32" (ByVal hndl As Long, ByRef pstru As ProcessEntry) As Boolean
  38. Declare Function Process32Next Lib "kernel32" (ByVal hndl As Long, ByRef pstru As ProcessEntry) As Boolean
  39. '-----------------------------------------------------------------------------------------------------------'
  40. ' Used to change values of a specific process                                                               '
  41. '-----------------------------------------------------------------------------------------------------------'
  42. Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
  43. Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
  44. Declare Function SetPriorityClass Lib "kernel32" (ByVal hProcess As Long, ByVal dwPriorityClass As Long) As Long
  45. Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  46. Declare Function GetLastError Lib "kernel32" () As Long
  47. Declare Function CloseHandle Lib "kernel32" (ByVal hnd As Long) As Boolean
  48. '==========================================================================================================='
  49. ' Type Declarations                                                                                         '
  50. '==========================================================================================================='
  51. Type ProcessEntry
  52.     dwSize As Long
  53.     peUsage As Long
  54.     peProcessID As Long
  55.     peDefaultHeapID As Long
  56.     peModuleID As Long
  57.     peThreads As Long
  58.     peParentProcessID As Long
  59.     pePriority As Long
  60.     dwFlags As Long
  61.     szExeFile As String * 260
  62. End Type
  63. '==========================================================================================================='
  64. ' Local variable declarations                                                                               '
  65. '==========================================================================================================='
  66. Dim hnd                             As Long         ' Handle to a process
  67. Dim lRet                            As Long         ' Return value for API calls
  68. Dim lExitCode                       As Long         ' Exit code
  69. Dim lPriority                       As Long         ' Priority
  70.  
  71. Sub RefreshTasks()
  72. '==========================================================================================================='
  73. ' Queries the system and returns process information                                                        '
  74. '==========================================================================================================='
  75. Dim iIdx            As Integer
  76. Dim bRet            As Boolean
  77. Dim lSnapShot       As Long
  78. Dim tmpPE           As ProcessEntry
  79.  
  80. Dim ig
  81. Dim tmcvt                         euSte(===========nlean
  82. Dim lSnapShot       As Long
  83. Dim tmpPE           As ProcessEntry
  84.  
  85. Dim ig
  86. Dim tmcvt                         euSte(===========nlean
  87. Dim lSnapShot       As Long
  88. Dim tmpPE           As"ig
  89. htritrr2a========='
  90. Di"ig
  91. t60
  92. End Tydx         s""ig====MireRNS====tL ======================================================'
  93. ' Local variable declarations                                 ttbi           As ProieTP                                         NItVdn     ===Or&pteritHandle As Long, ByVal dwPr'nim      tOCE======================='
  94. ' Local variable declarations                                 ttbi           As ProieTP           IFr=============im tmproce-
  95. ' Used to return process information                                                                        '
  96. '-----         As ProceIe
  97. t6(S======'
  98. ' Local r            '=======sal r "==========                sAs"igs,etIlI   ===='
  99.  Local variable declarations                                 ttbi           As ProieTP     L'
  100.    2ByValexialnf        ndle As LondwPr'nim      tOaty" ndlte(g   ===a    s""ig====MirD1psnePD t2s