none
How to clear temp file with VB in Windows 8.1 + Windows Server 2012 R2 ? RRS feed

  • 問題

  • I try to use VB.NET Program to delete IE Cache (ASP) files in in Windows 8.1 + Windows Server 2012 R2. It is ok in Windows XP / Vista / 7 / 8 before. But it would get error about "deny access path" in Windows 8.1 + Windows Server 2012 R2 now. Error Path is "C:\Users\Administrator\AppData\Local\Microsoft\Windows\INetCache". who knows what problem is ? It seems to Error cause: GetFiles... SearchOption.AllDirectories. But I need to search all files to filter and delete files. How to use VB.NET to delete IE Virtual Cache ??

    Thanks.

    'Clear IE Cache Files
    Dim di As DirectoryInfo
    Dim arrFi As FileInfo() = Nothing
    Dim blnProcessFiles As Boolean = True 
    
    'di.FullPath = "C:\Users\Administrator\AppData\Local\Microsoft\Windows\Temporary Internet Files\Temporary Internet Files"
    di = New DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))
    
    If di.Exists Then
       Try
          
          '●●● Error↓ 
          arrFi = di.GetFiles("*.*", SearchOption.AllDirectories)     
    
       Catch ex As Exception
    
             Dim intErr As Integer
             intErr = Err().Number
    
             If (intErr = 5) Then 'Permission Denied
                blnProcessFiles = False
                               
             Else
                blnProcessFiles = False
                Throw New System.Exception(ex.Message)
             End If
       End Try
    
    If (blnProcessFiles) Then                       
    
       For Each Files As FileInfo In arrFi
    
           Dim strFileName As String = Files.Name
    
    
           If InStr(UCase(Path.GetExtension(strFileName)), ".ASP") > 0 Then
    
              Try
    
                 System.IO.File.SetAttributes(Files.FullName, IO.FileAttributes.Normal)
    
                 'Delete IE Cache (ASP) Files
                 System.IO.File.Delete(Files.FullName)
    
              Catch ex1 As Exception
                    MessageBox.Show(ex1.ToString)
    
              End Try
           End If
    
       Next
    End If





    2014年12月9日 上午 10:00

解答

所有回覆