Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to activate, kill the process after knowing their pr
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00321552
Message ID:
00483614
Vues:
21
I get it.

Thanks to you, George Tasker, Ramon Jaquez, and Gary Foster!
*	Kill Any App running on NT through the Win32 API
*	Kills it dead, no questions!
*       Dependency on Ramon's enumproc.dll to find PID 
clear
nNothing = .Null.
If GetPID("Excel") != -65535
nNothing = KillPID(GetPID("Excel"))
Endif

? nNothing

Function  GetPID
Parameters cProgName
nNothing = Sys(1104)  && Undocumented way to free up memory buffers MSKBQ269284
nPID = .Null.
Declare Integer OpenProcList in enumproc.dll
Declare Integer GetFirstProc  in enumproc.dll Integer hhandle, Integer @ lpdwprocid, Short@ lpwprocid16, String@ lpzprocname
Declare Integer GetNextProc  in enumproc.dll Integer hhandle, Integer @ lpdwprocid, Short@ lpwprocid16, String@ lpzprocname
Declare Integer CloseProcList in enumproc.dll Integer hHandle
Local cProcName, nProcID, nProcID16, nHandle
cProcName = Replicate(Chr(0), 260)
nProcID = 0
nProcID16 = 0
nHandle = OpenProcList()
If nHandle = 0
? 'Error getting procedure list...'
Return
Endif
If GetFirstProc(nHandle, @nprocid, @nprocid16, @cprocname) != 0
Do While GetNextProc(nHandle, @nprocid, @nprocid16, @cprocname) != 0
If Lower(cProgName) $ Lower(Left(cprocname, At(Chr(0), cprocname)-1) )
nPID = nProcID
EndIf
EndDo
Else
? 'Error getting first process...'
Endif
nPID = IIf( IsNull(nPID),-65535,nPID)
Return nPID
EndFunc

Function KillPID
Parameters nPID
#DEFINE PROCESS_TERMINATE (0x0001)
#DEFINE PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \0xFFF)
#DEFINE LOC_STRLEN 300
DECLARE INTEGER OpenProcess IN WIN32API INTEGER nAccess, INTEGER nHandleFlag, INTEGER hProcess
hProcess = OpenProcess(PROCESS_TERMINATE + PROCESS_VM_READ,0,nPID)	
IF hProcess > 0
? hProcess
Declare Short TerminateProcess in Win32API as KillProc Integer hProcess, Integer uExitCode
nResult = KillProc(hProcess,0)
If nResult = 0
? "TerminateProcess() could not kill process handle requested"
Else
? "Process terminated"
EndIf
Clear DLLS
else
endif
Return  .t.
EndFunc
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform