Guidance
指路人
g.yi.org
software / rapidq / Examples / Memory Process Thread Message / EnumProcesses.rqb

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     $OPTIMIZE ON
     $TYPECHECK ON

     CONST NUM_PROCESSES = 1024

     CONST NULL = 0

' See the MSDN Documentation at http://shrinkster.com/282
     CONST STARTF_USESHOWWINDOW    = &H00000001
     CONST STARTF_USESIZE          = &H00000002
     CONST STARTF_USEPOSITION      = &H00000004
     CONST STARTF_USECOUNTCHARS    = &H00000008
     CONST STARTF_USEFILLATTRIBUTE = &H00000010
     CONST STARTF_RUNFULLSCREEN    = &H00000020  ' ignored for non-x86 platforms
     CONST STARTF_FORCEONFEEDBACK  = &H00000040
     CONST STARTF_FORCEOFFFEEDBACK = &H00000080
     CONST STARTF_USESTDHANDLES    = &H00000100

' See the MSDN Documentation at http://shrinkster.com/284
     CONST SW_HIDE             = 0
     CONST SW_SHOWNORMAL       = 1
     CONST SW_NORMAL           = 1
     CONST SW_SHOWMINIMIZED    = 2
     CONST SW_SHOWMAXIMIZED    = 3
     CONST SW_MAXIMIZE         = 3
     CONST SW_SHOWNOACTIVATE   = 4
     CONST SW_SHOW             = 5
     CONST SW_MINIMIZE         = 6
     CONST SW_SHOWMINNOACTIVE  = 7
     CONST SW_SHOWNA           = 8
     CONST SW_RESTORE          = 9
     CONST SW_SHOWDEFAULT      = 10
     CONST SW_FORCEMINIMIZE    = 11
     CONST SW_MAX              = 11

' See the MSDN Documentation at http://shrinkster.com/282
     TYPE STARTUPINFO
      cb AS LONG
      lpReserved AS LONG
      lpDesktop AS LONG
      lpTitle AS LONG
      dwX AS LONG
      dwY AS LONG
      dwWidth AS LONG
      dwHeight AS LONG
      dwCharWidth AS LONG
      dwCharHeight AS LONG
      dwFillAttribs AS LONG
      dwFlags AS LONG
      wShowWindow AS LONG
      cbReserved2 AS LONG
      lpReserved2 AS LONG
      hStdInput AS LONG
      hStdOutput AS LONG
      hStdError AS LONG
     END TYPE

' See the MSDN Documentation at http://shrinkster.com/283
     TYPE PROCESS_INFORMATION
      hProcess AS LONG
      hThread AS LONG
      dwPID AS LONG
      dwTID AS LONG
     END TYPE

' See the MSDN Documentation at http://shrinkster.com/285
     DECLARE FUNCTION CreateProcess LIB "kernel32" ALIAS "CreateProcessA" (BYREF applicationName AS STRING, BYREF commandLine AS STRING, processAttribs AS LONG, threadAttribs AS LONG, inheritHandles AS LONG, flags AS LONG, enviroment AS LONG, BYREF currentDirectory AS STRING, lpStartupInfoStruct AS LONG, lpProcessInformationStruct AS LONG) AS LONG
' See the MSDN Documentation at http://shrinkster.com/286
     DECLARE FUNCTION EnumProcesses LIB "psapi" ALIAS "EnumProcesses" (arrayPointer AS LONG, arraySize AS LONG, BYREF arrayUsed AS LONG) AS LONG

     DECLARE FUNCTION ProcessExists(pid AS LONG) AS INTEGER

'######################
'# Launch the process #
'######################

     DIM si AS STARTUPINFO
     WITH si
      .cb = SIZEOF(si)
      .lpReserved = NULL
      .lpDesktop = NULL
      .lpTitle = NULL
      .dwX = 0
      .dwY = 0
      .dwWidth = 0
      .dwHeight = 0
      .dwCharWidth = 0
      .dwCharHeight = 0
      .dwFillAttribs = 0
      .dwFlags = STARTF_USESHOWWINDOW
      .wShowWindow = SW_MINIMIZE
      .cbReserved2 = 0
      .lpReserved2 = NULL
      .hStdInput = NULL
      .hStdOutput = NULL
      .hStdError = NULL
     END WITH

     DIM pi AS PROCESS_INFORMATION
'pi.dwPID = 255

     DIM siMem AS QMEMORYSTREAM, piMem AS QMEMORYSTREAM 'This step must be done because UDTs are not stored in the right order in memory
     siMem.WriteUDT(si)
     piMem.WriteUDT(pi)

     DEFSTR appName =  "", cmdLine = "notepad.exe", curDir = ""

     CreateProcess(appName, cmdLine, NULL, NULL, 0, 0, NULL, curDir, siMem.Pointer, piMem.Pointer)

     piMem.Position = 0 'reset pointer to the begining so we can read the newly populated PROCESS_INFORMATION struct
     piMem.ReadUDT(pi)

     siMem.CLOSE
     piMem.CLOSE

     PRINT "Notepad is running as " + STR$(pi.dwPID)

'#########################
'# Check for the process #
'#########################

     WHILE (ProcessExists(pi.dwPID) = 1)
      SLEEP .1
     WEND

     PRINT "Notepad is no longer running..."

'#############
'# Functions #
'#############

     FUNCTION ProcessExists(pid AS LONG) AS INTEGER
      DIM processes(NUM_PROCESSES) AS LONG, size AS LONG, used AS LONG
      size = = NUM_PROCESSES * SIZEOF(LONG)

      EnumProcesses(VARPTR(processes(0)), size, used)

      used = used / SIZEOF(LONG)

      Result = 0

      DEFINT i
      FOR i = 0 TO used
       IF (processes(i) = pid) THEN
        Result = 1
        EXIT FUNCTION
       END IF
      NEXT i
     END FUNCTION
掌柜推荐
 
 
¥738.00 ·
 
 
¥1,480.00 ·
 
 
¥397.00 ·
 
 
¥950.00 ·
 
 
¥264.00 ·
 
 
¥1,005.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2005-04-16 12:36:59