Hello, I searched the forum for solving this issue, but couldn't find one. I made an uninstaller which uninstalls certain application. However this application have lots of read-only files and folders and my uninstaller isn't able to remove any of them. So I need a code that would do so. Thanks in advance.
Here's the uninstaller code that I have:
Here's the uninstaller code that I have:
VB.NET:
Imports System.IO
Dim path As String
Dim tempstring As String
Dim totalbytes As Long
Private Sub Uninstall_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
path = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp", "InstallLocation", "")
If path = "" Then
End
End If
totalbytes = GetFolderSize(path, True)
IO.Directory.Delete(path & "\", True)
My.Computer.Registry.LocalMachine.DeleteSubKey("\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp\")
Application.DoEvents()
End Sub
Private Sub Uninstall_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
On Error Resume Next
GetFileCount(My.Computer.FileSystem.SpecialDirectories.Programs & "\MyApp\")
tempstring = "@echo off"
tempstring = tempstring & vbCrLf & "TASKKILL /F /IM " & Chr(34) & "uninstall.exe" & Chr(34)
tempstring = tempstring & vbCrLf & "ping localhost > nul"
tempstring = tempstring & vbCrLf & "del " & Chr(34) & path & "\uninstall.exe" & Chr(34)
tempstring = tempstring & vbCrLf & "del " & Chr(34) & My.Computer.FileSystem.SpecialDirectories.Desktop & "\MyApp.lnk" & Chr(34)
tempstring = tempstring & vbCrLf & "del " & Chr(34) & My.Computer.FileSystem.SpecialDirectories.Programs & "\Project\" & "MyApp.lnk" & Chr(34)
tempstring = tempstring & vbCrLf & "rmdir " & Chr(34) & My.Computer.FileSystem.SpecialDirectories.Programs & "\Project\" & Chr(34)
tempstring = tempstring & vbCrLf & "rmdir " & Chr(34) & path & "\" & Chr(34)
tempstring = tempstring & vbCrLf & "rmdir " & Chr(34) & Directory.GetParent(path).ToString & Chr(34)
tempstring = tempstring & vbCrLf & "REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp /f"
tempstring = tempstring & vbCrLf & "del %0"
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.bat", tempstring, False, System.Text.Encoding.Default)
Shell(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.bat", AppWinStyle.Hide)
End Sub