Match desktop file name to name on listview

bluezap

New member
Joined
Oct 31, 2015
Messages
4
Programming Experience
5-10
Hi, I'm writing a basic uninstaller in vb.net
I got everything down but I need help with one small aspect.

When the user drags and drops a software on the uninstaller I need it to automatically match the listed software on the uninstaller and start the uninstallation dialog immedietely.
The way that U have it now, the user has to select the name of the software from the listview and then drag that application from the desktop to start the uninstall.
How do I cut out the need for the user to select the name of the software from the listview.

VB.NET:
Imports Microsoft.Win32
Imports System.IO


Public Class Form1


    Private Sub Form1_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim Files() As String
            Files = e.Data.GetData(DataFormats.FileDrop)
            Dim sReader As New StreamReader(Files(0))


            Dim file_name As String = Path.GetFileNameWithoutExtension(Files(0))


            
            For Each LI As ListViewItem In ListView1.SelectedItems
                If ListView1.SelectedItems(0).Text = file_name Then
                    If LI.SubItems(1).Text.ToLower.StartsWith("msiexec") Then
                        Dim p As New Process
                        p.StartInfo.Arguments = LI.SubItems(1).Text.Remove(0, LI.SubItems(1).Text.IndexOf(" "))
                        p.StartInfo.FileName = "msiexec.exe"
                        p.Start()
                    Else
                        Process.Start(LI.SubItems(1).Text)
                    End If
                End If
            Next
        End If


    End Sub


    Private Sub Form1_DragEnter(sender As Object, e As DragEventArgs) Handles Me.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Me.AllowDrop = True
        For Each AI As AppInfo In GetInstalledApps()
            If AI.UnInstallPath IsNot Nothing Then
                Dim LI As New ListViewItem
                LI.Text = AI.Name
                LI.SubItems.Add(AI.UnInstallPath.Replace("""", ""))
                LI.SubItems.Add(AI.SilentUnInstallPath)
                ListView1.Items.Add(LI)
            End If
        Next


    End Sub


    Structure AppInfo
        Dim Name As String
        Dim UnInstallPath As String
        Dim SilentUnInstallPath As String
    End Structure


    Function GetInstalledApps() As List(Of AppInfo)
        Dim DestKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
        Dim iList As New List(Of AppInfo)
        For Each App As String In Registry.LocalMachine.OpenSubKey(DestKey).GetSubKeyNames
            iList.Add(New AppInfo With {.Name = Registry.LocalMachine.OpenSubKey(DestKey & App & "\").GetValue("DisplayName"), _
                       .UnInstallPath = Registry.LocalMachine.OpenSubKey(DestKey & App & "\").GetValue("UninstallString"), _
                       .SilentUnInstallPath = Registry.LocalMachine.OpenSubKey(DestKey & App & "\").GetValue("QuietUninstallString")})
        Next
        Return iList
    End Function


    Public Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
        For Each LI As ListViewItem In ListView1.SelectedItems
            If LI.SubItems(1).Text.ToLower.StartsWith("msiexec") Then
                Dim p As New Process
                p.StartInfo.Arguments = LI.SubItems(1).Text.Remove(0, LI.SubItems(1).Text.IndexOf(" "))
                p.StartInfo.FileName = "msiexec.exe"
                p.Start()
            Else
                Process.Start(LI.SubItems(1).Text)
            End If
        Next
    End Sub

Any help would be much appreciated!
 

Latest posts

Back
Top