2012-02-26 67 views
0

此代碼獲取所有具有卸載條目及其應用程序路徑的軟件。但是,鑑於我有應用程序路徑,我不知道該軟件的主要.exe的名稱。有什麼方法可以找到找到的應用程序的主要.exe文件?VB.NET/C#查找已安裝的軟件名稱和應用程序路徑後如何找到exe名稱

'Declare the string to hold the list: 
    Dim Software As String = Nothing 

    'The registry key: 
    Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 
    Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey) 
     'Let's go through the registry keys and get the info we need: 
     Dim j As Integer = 0 
     For Each skName As String In rk.GetSubKeyNames() 
      Using sk As RegistryKey = rk.OpenSubKey(skName) 
       Try 
        'If the key has value, continue, if not, skip it: 
        If Not (sk.GetValue("DisplayName") Is Nothing) And Not (sk.GetValue("InstallLocation") Is Nothing) And 
        Not (sk.GetValue("InstallLocation") = "") Then 
         Dim instanceremoved As Boolean = False 
         For Each item As ListViewItem In ListInstalled.Items 
          If item.SubItems.Item(1).Text = sk.GetValue("InstallLocation") Then 
           item.Remove() 
           instanceremoved = True 
          End If 
         Next 

         If instanceremoved = False Then 
          Dim itemAdd As ListViewItem = ListInstalled.Items.Add(sk.GetValue("DisplayName")) 
          itemAdd.SubItems.Add(sk.GetValue("InstallLocation")) 

         End If 

        End If 
        'No, that exception is not getting away... :P 
       Catch ex As Exception 
        MsgBox(ex) 
       End Try 
      End Using 
      j = j + 1 
     Next 
    End Using 

回答

0

主Exe未存儲在註冊表中uninstall命令存儲在UninstallString項中。

+0

哪裏存放的主要exes? – user670186 2012-02-26 16:27:17

+0

在文件系統上的不同位置不在註冊表中 – 2012-02-26 17:20:04

+0

是的,但是有沒有一些標準的方法來檢索已安裝軟件的主要exe名稱或用戶是否必須自己選擇它? – user670186 2012-02-26 17:57:14

相關問題