Eccolo, era su ioprogrammo n.79, praticamente chiude un processo di quel nome ad un ora predefinita:
codice:
Private Declare Function CreateToolhelp32Snapshot 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 CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Const TH32CS_SNAPALL = 15
Const TH32CS_INHERIT = &H80000000
Dim application As String
Dim hours, minutes As Integer
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 * 260
End Type
Public Function getexename(ByVal fullpath As String) As String
Dim exename As String
exename = fullpath
Do While InStr(exename, "\")
exename = Right(exename, Len(exename) - InStr(exename, "\"))
Loop
getexename = exename
End Function
Public Function killapp(ByVal application As String)
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim phandle, i As Long
Dim exename, app As String
app = UCase(application)
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
i = Process32First(hSnapShot, uProcess)
Do While i
exename = Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, _
InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0))
exename = UCase(getexename(exename))
If exename = app Then
phandle = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
TerminateProcess phandle, 0
End If
i = Process32Next(hSnapShot, uProcess)
Loop
CloseHandle hSnapShot
End Function
Private Sub Form_Load()
Timer1.Interval = 1000
'Settare il nome del programma e il
'momento della sua chiusura
application = "notepad.exe"
hours = 18
minutes = 40
End Sub
Private Sub Timer1_Timer()
If (Round(Timer) = hours * 3600 + minutes * 60) Then
killapp application
End If
End Sub