|
-
Oct 5th, 2000, 02:40 PM
#1
Thread Starter
New Member
Hi,
Here is the listing. The stars specify where is the problem.
Private Sub Com_SupFichTemp_Click()
'Kill files
Dim sChemin As String
For i = 0 To File_FichTemp.ListCount
sChemin = File_FichTemp.Path + "\" + File_FichTemp.List(i)
*** If File_FichTemp.List(i).Locked = True Then
Kill sChemin
End If
Next i
Form_EpurationFich.Refresh
End Sub
I want to kill some files .tmp but some of then are used by the application (in VB6) I want to kill them through the application and it's make me problems.
Also I would like to add another condition, but for that I need to know the file's date and make the second condition with it.
Thanks!
[Edited by PomHappy on 10-06-2000 at 09:37 AM]
-
Oct 5th, 2000, 03:02 PM
#2
Try this:
Code:
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
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
Public Function KillApp(myName As String) As Boolean
Const PROCESS_ALL_ACCESS = 0
Dim uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim hSnapshot As Long
Dim szExename As String
Dim exitCode As Long
Dim myProcess As Long
Dim AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error GoTo Finish
appCount = 0
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szexeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
If Right$(szExename, Len(myName)) = LCase$(myName) Then
KillApp = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = ProcessNext(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function
Private Sub Com_SupFichTemp_Click()
'Kill files
Dim sChemin As String
For i = 0 To File_FichTemp.ListCount
sChemin = File_FichTemp.Path + "\" + File_FichTemp.List(i)
*** If File_FichTemp.List(i).Locked = True Then
Call KillApp(sChemin)
Kill sChemin
End If
Next i
Form_EpurationFich.Refresh
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|