Re: How to determine which process to kill ???

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



OK, the question is "What to do when file is open (i.e. held by
another process, for example by process used to open it)?"
What I need to do is to close it and then delete it. How can I do
that?


On Fri, 23 Sep 2005 15:09:55 -0400, "Mike Labosh"
<mlabosh@xxxxxxxxxxx> wrote:

>1. When you create your temp files in your application, you should hold onto
>the filenames that were used, like, in a string array or something:
>
>' untested air code
>
>Private _tmpFileList As New ArrayList()
>
>Private Function createTempFile() As String
>
> Dim filename As String = _
> System.IO.Path.GetTempFileName()
>
> _tmpFileList.Add(filename)
>
>End Function
>
>Private Sub cleanupTempFiles()
>
> For Each filename As String In _tmpFileLilst
> Try
> File.Delete filename
> ' Catch -- do something here for FileNotFound or File is open
> Finally
> System.IO.Path.Delete(filename)
> End Try
> Next
>
>End Sub
>
>You could also accumulate your FileStream's or StreamReader or Writer in a
>HashTable keyed off the filenames you get from createTempFile()
>
>> for each file in temp
>> if file is open then
>> process = get process using this file
>> kill(process)
>> end if
>>
>> delete file
>> next
>
>2. That right there sounds dangerous to me. What if you accidentally kill
>some system related process or Windows Service or your AntiVirus agent(s).
>You could destabilize the system. As a rule, your application should only
>be deleting files that it created.

.



Relevant Pages

  • Re: How to determine which process to kill ???
    ... "When you kill a man, ... >>the filenames that were used, like, in a string array or something: ... >>Private Function createTempFile() As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: common dialog w/api instead of COMDLG32.OCX, possible?
    ... As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As ... Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias ... Public Property Get FileNameAs String ...
    (microsoft.public.vb.winapi)
  • Re: Incompatibility between Access 2003 and Access 2002
    ... Private WithEvents mlst As ListBox ... Private mot As ObjectType ... Public DisplayField As String ... Dim prm As DAO.Parameter ...
    (microsoft.public.access.modulesdaovba)
  • Re: GetOpenFilename With MultiSelect Intermittently Returns String
    ... ByVal lpWindowName As String) As Long ... Private Declare Function lstrlen Lib "kernel32" _ ... Private Const OFN_ALLOWMULTISELECT As Long = &H200 ...
    (microsoft.public.excel.programming)
  • Re: Getting Windows Display Name
    ... Private Type WKSTA_USER_INFO_1 ... usri3_script_path As Long 'Pointer to a Unicode string specifying the path for the user's logon script file. ... Dim bufptr As Long ... Public Property Get PasswordAgeAs Long ...
    (microsoft.public.access.modulesdaovba)