This question is asking for improvements to the code I wrote to remove MS & Chrome files that keep being downloaded to my computer. In this case it is W7 64 bit with VS 2019 and I only use Firefox.
I have VS set to no updates and the only MS update is MS Security Essentials which is set to
Check for Updates & Let me choose to Download & Install"
Every time I start my computer MS sends this message and If I let the computer idle for
10 min I get 5 of these messages.
Warning: Failed to get value SOFTWARE\Microsoft\VisualStudio\16.11\ExtensionManager/ExtensionsAutoUpdated: Object reference not set to an instance of an object.
[13d0:0001][2024-08-19T10:13:50] No update since last run. Skipping current operation.
Please I am a novice and even after using the App for a few days I wonder if it is has any value. I did learn how System IO works so the time spent was worth it IMHO.
What I have tried:
Imports System.IO
Imports System.Security.Principal
Public Class frmStart
Public Sub frmStart_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
If Asc(e.KeyChar) = 27 Then
Application.Exit()
End If
End Sub
Private Sub btnVCache_Click(sender As Object, e As EventArgs) Handles btnVCache.Click
lstFiles.Items.Clear()
Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Google\Chrome\User Data\Default\Cache\Cache_Data\"
Process.Start(folderPath)
End Sub
Private Sub btnVTemp_Click(sender As Object, e As EventArgs) Handles btnVTemp.Click
lstFiles.Items.Clear()
Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Temp\"
Process.Start(folderPath)
End Sub
Private Sub btnDelCache_Click(sender As Object, e As EventArgs) Handles btnDelCache.Click
Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Google\Chrome\User Data\Default\Cache\Cache_Data\"
Dim filePattern As String = "f*"
Dim files As IEnumerable(Of String) = Directory.EnumerateFiles(folderPath, filePattern)
lstFiles.Items.Clear()
Try
If files.Any() Then
gvType = "6"
frmAlert.ShowDialog()
gvType = "7"
frmAlert.ShowDialog()
If gvResult = "YES" Then
For Each fileName As String In Directory.GetFiles(folderPath)
Dim dirInfo As New DirectoryInfo(fileName)
Dim fC As String = fileName.Replace(folderPath, String.Empty)
If fC.Substring(0, 1) = "f" Then
lstFiles.Items.Add(fileName.Replace(folderPath, String.Empty))
My.Computer.FileSystem.DeleteFile(fileName, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.ThrowException)
End If
Next
gvType = "3"
frmAlert.ShowDialog()
ElseIf gvResult = "NO" Then
Dim file As String = folderPath.Replace(folderPath, String.Empty)
For Each file In files
Dim fileName As String = Path.GetFileName(file)
lstFiles.Items.Add(fileName)
Next
End If
Else
gvType = "5"
frmAlert.ShowDialog()
End If
Catch ex As UnauthorizedAccessException
MessageBox.Show("Access to the folder is denied.")
Catch ex As DirectoryNotFoundException
MessageBox.Show("The specified folder does not exist.")
Catch ex As Exception
MessageBox.Show("An error occurred: " & ex.Message)
End Try
End Sub
Private Sub btnDelTemp_Click(sender As Object, e As EventArgs) Handles btnDelTemp.Click
Dim folderPath As String = "C:\Users\Dwight\AppData\Local\Temp\"
Dim files As String() = Directory.GetFiles(folderPath, "dd*")
lstFiles.Items.Clear()
If files.Length = 0 Then
gvType = "1"
frmAlert.ShowDialog()
Exit Sub
End If
gvType = "2"
frmAlert.ShowDialog()
If gvResult = "YES" Then
For Each file As String In files
lstFiles.Items.Add(file.Replace(folderPath, String.Empty))
My.Computer.FileSystem.DeleteFile(file, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.ThrowException)
Next
gvType = "3"
frmAlert.ShowDialog()
ElseIf gvResult = "NO" Then
gvType = "4"
frmAlert.ShowDialog()
Exit Sub
End If
End Sub
Private Sub btnOpenRB_Click(sender As Object, e As EventArgs) Handles btnOpenRB.Click
lstFiles.Items.Clear()
Dim userSid As String = WindowsIdentity.GetCurrent().User.Value
Dim recycleBinPath As String = String.Format("C:\$Recycle.Bin\{0}", userSid)
Process.Start("explorer.exe", recycleBinPath)
End Sub
End Class
frmAlert
Public Class frmAlert
Private Sub btnYes_Click(sender As Object, e As EventArgs) Handles btnYes.Click
gvResult = "YES"
Close()
End Sub
Private Sub btnNo_Click(sender As Object, e As EventArgs) Handles btnNo.Click
gvResult = "NO"
Close()
End Sub
Public Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
Close()
End Sub
Public Sub SetOKTrue()
btnYes.Visible = False
btnNo.Visible = False
btnOK.Visible = True
End Sub
Public Sub SetOKFalse()
btnYes.Visible = True
btnNo.Visible = True
btnOK.Visible = False
End Sub
Private Sub frmAlert_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If gvType = "1" Then
tbAlert.Text = vbCrLf & "No Files to Delete"
SetOKTrue()
ElseIf gvType = "2" Then
tbAlert.Text = vbCr & "YES to Delete Files" & vbCrLf & vbCrLf & "NO to EXIT "
SetOKFalse()
ElseIf gvType = "3" Then
tbAlert.Text = vbCrLf & "Files Deleted"
SetOKTrue()
ElseIf gvType = "4" Then
tbAlert.Text = vbCrLf & "NO Files DELETED"
SetOKTrue()
ElseIf gvType = "5" Then
tbAlert.Text = vbCrLf & "NO Files With" & " f " & "FOUND"
SetOKTrue()
ElseIf gvType = "6" Then
tbAlert.Text = vbCrLf & "Files FOUND"
SetOKTrue()
ElseIf gvType = "7" Then
tbAlert.Text = vbCr & "Yes to Delete Files" & vbCrLf & vbCrLf & "NO ONLY View Files"
SetOKFalse()
End If
End Sub
End Class
Module
Module AlertModule
Public gvType As String
Public gvResult As String
End Module