Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Finding If a program is running
Message
De
05/09/2005 05:26:16
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
05/09/2005 01:20:59
Sunil Kejariwal
The Software Workshop
Mumbai, Inde
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 6
Divers
Thread ID:
01046715
Message ID:
01046738
Vues:
19
>I want to check in the begining of my program weather a particular exe is already running or not ?
>
>If it is not running then I want to run it programatically .
>
>Is it possible ? Pl. help.
>
>Thanks in Advance.
>
>Regards
lcParticularExe = "notepad.exe"
GetProcessesRunning()
select ProcList
locate for lower(szExeFile) == lower(m.lcParticularExe)
llIsRunning = !eof()
use in 'ProcList'

Function GetProcessesRunning
  #Define TH32CS_SNAPPROCESS  2
  #Define TH32CS_SNAPTHREAD   4
  #Define TH32CS_SNAPMODULE   8
  #Define MAX_PATH          260
  #Define PE32_SIZE  296

  Declare Integer CloseHandle In kernel32 Integer hObject
  Declare Integer CreateToolhelp32Snapshot In kernel32;
    INTEGER dwFlags, Integer th32ProcessID
  Declare Integer Process32First In kernel32;
    INTEGER hSnapshot, String @ lppe
  Declare Integer Process32Next In kernel32;
    INTEGER hSnapshot, String @ lppe
  Declare RtlMoveMemory In WIN32API ;
    INTEGER @DestNumeric, ;
    STRING @pVoidSource, ;
    INTEGER nLength

  Create Cursor ProcList ;
    (ProcessID i,;
    cntThreads i,;
    ParentPID i,;
    szExeFile m)

  Local hSnapshot, lcBuffer, lSuccess

  hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0)
  lcBuffer = Int2Str(PE32_SIZE) + Replicate(Chr(0), PE32_SIZE-4)

  lSuccess = ( Process32First(hSnapshot, @lcBuffer) # 0 )
  Do While m.lSuccess
    PROCESSENTRY32_ToCursor(m.lcBuffer)
    lSuccess = ( Process32Next(hSnapshot, @lcBuffer) # 0 )
  Enddo
  CloseHandle(hSnapshot)
Endfunc

Function PROCESSENTRY32_ToCursor
  Lparameters tcBuffer
  Local szExeFile
  m.szExeFile = Substr(m.tcBuffer,37)
  m.szExeFile = Substr(m.szExeFile, 1, ;
    AT(Chr(0),m.szExeFile)-1)
  Insert Into ProcList ;
    (ProcessID,	cntThreads, ParentPID, szExeFile) ;
    values ;
    (Substr2Num(m.tcBuffer,9,4), ;
    Substr2Num(m.tcBuffer,21,4), ;
    Substr2Num(m.tcBuffer,25,4), ;
    m.szExeFile	)
Endfunc

Function Substr2Num
  Lparameters tcStr, tnStart, tnSize
  Return Str2Num(Substr(m.tcStr, m.tnStart, m.tnSize), m.tnSize)
Endfunc

Function Str2Num
  Lparameters tcStr,tnSize
  Local m.lnValue
  m.lnValue=0
  RtlMoveMemory(@lnValue, m.tcStr, m.tnSize)
  Return m.lnValue
Endfunc

Function Int2Str
  Lparameters tnValue, tnSize
  Local ix, lcReturn
  m.tnSize = Iif(Empty(m.tnSize),4,m.tnSize)
  lcReturn = ''
  For ix=1 To m.tnSize
    m.lcReturn = m.lcReturn + ;
      Chr(Bitand(Bitrshift(m.tnValue, (m.ix-1)*8),0xFF))
  Endfor
  Return m.lcReturn
Endfunc
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform