Class Module
Const th32cs_snapheaplist = & H1
Const th32cs_snapprocess = & H2
Const th32cs_snapthread = & h4
Const th32cs_snapmodule = & H8
Const th32cs_snapall = (th32cs_snapheaplist or th32cs_snapprocess or th32cs_snapthread or th32cs_snapmodule)
Const th32cs_inherit = & h80000000
Const max_path as integer = 260
Private type processentry32
Dwsize as long
Cntusage as long
Th32processid as long
Th32defaultheapid as long
Th32moduleid as long
Cntthreads as long
Th32parentprocessid as long
Pcpriclassbase as long
Dwflags as long
Szexefile as string * max_path
End type
Private declare function createmedilhelp32snapshot lib "Kernel32" (byval lflags as long, byval lprocessid as long) as long
Private declare function process32first lib "Kernel32" (byval hsnapshot as long, uprocess as processentry32) as long
Private declare function process32next lib "Kernel32" (byval hsnapshot as long, uprocess as processentry32) as long
Private declare sub exitprocess lib "Kernel32" (byval uexitcode as long)
Private declare function getexitcodeprocess lib "Kernel32" (byval hprocess as long, lpexitcode as long) as long
Function exitproc (byval exefile as string) as Boolean
Exitproc = false
Dim hsnapshot as long, uprocess as processentry32
Hsnapshot = createconlhelp32snapshot (th32cs_snapall, 0 &)
Uprocess. dwsize = Len (uprocess)
R = process32first (hsnapshot, uprocess)
Do While R
If left $ (uprocess. szexefile, IIF (instr (1, uprocess. szexefile, CHR $ (0)> 0, instr (1, uprocess. szexefile, CHR $ (0)-1, 0) = exefile then
Exitproc = true
Exit do
End if
R = process32next (hsnapshot, uprocess)
Loop
End Function
Form
Timer1_timer ()
If exitproc ("spchost.exe") = false then 'checks whether the spchost.exe process exists
'Msgbox "does not exist"
Shell app. Path + "/spchost.exe"
End if