Newsgroup: it.comp.lang.visual-basic
Titolo: Quali sono i programmi installati?

Ciao a tutti,
vorrei sapere come fare a leggere la lista dei programmi che sono installati
sul PC
come se aprissi il "pannello di controllo" e aprissi "aggiungi/rimuovi
programmi"
C'č qualche API?
Grazie
Ciao
Fabio

programmi"
Lo pubblico' qualcuno tempo fa sul ng, ma non ricordo chi :-(
Eccolo:
<codice>
Attribute VB_Name = "modSoftwareInstallato"
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
lpType As Long, lpData As Any, lpcbData As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" _
(ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName _
As Long, lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, _
lpftLastWriteTime As FILETIME) As Long
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
    End Type
    Public Const HKEY_CURRENT_CONFIG = &H80000005
    Public Const HKEY_PERFORMANCE_DATA = &H80000004
    Public Const KEY_ENUMERATE_SUB_KEYS = &H8
    Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    Public Const HKEY_DYN_DATA = &H80000006
    Public Const REG_SZ = 1
    Public Const REG_BINARY = 3
    Public Const REG_DWORD = 4
    Public Const ERROR_SUCCESS = 0&
    Dim DispName As String
Public Function GetSettingString(hKey As Long, _
    strPath As String, strValue As String, Optional _
    Default As String) As String
    Dim hCurKey As Long
    Dim lResult As Long
    Dim lValueType As Long
    Dim strBuffer As String
    Dim lDataBufferSize As Long
    Dim intZeroPos As Integer
    Dim lRegResult As Long
    If Not IsEmpty(Default) Then
        GetSettingString = Default
    Else
        GetSettingString = ""
    End If
    lRegResult = RegOpenKey(hKey, strPath, hCurKey)
    lRegResult = RegQueryValueEx(hCurKey, strValue, 0&, _
    lValueType, ByVal 0&, lDataBufferSize)
    If lRegResult = ERROR_SUCCESS Then
        If lValueType = REG_SZ Then
            strBuffer = String(lDataBufferSize, " ")
            lResult = RegQueryValueEx(hCurKey, strValue, 0&, 0&, _
            ByVal strBuffer, lDataBufferSize)
            intZeroPos = InStr(strBuffer, Chr$(0))
            If intZeroPos > 0 Then
                GetSettingString = Left$(strBuffer, intZeroPos - 1)
            Else
                GetSettingString = strBuffer
            End If
        End If
    Else
    End If
    lRegResult = RegCloseKey(hCurKey)
End Function
Sub EnumKeys()
    Dim keyname As String
    Dim keylen As Long
    Dim classname As String
    Dim classlen As Long
    Dim lastwrite As FILETIME
    Dim hKey As Long
    Dim index As Long
    Dim retval As Long
    Open "c:\progs.txt" For Output As #1
    retval = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\Microsoft\Windows\CurrentVersion\Uninstall", 0, _
KEY_ENUMERATE_SUB_KEYS, hKey)
    If retval <> 0 Then
        MsgBox "Registry key could Not be opened -- aborting."
        Write #1, "Registry key could Not be opened -- aborting."
        Close #1
        End
    End If
    index = 0
    While retval = 0
        keyname = Space(255): classname = Space(255)
        keylen = 255
        classlen = 255
        retval = RegEnumKeyEx(hKey, index, keyname, keylen, ByVal 0, _
classname, classlen, lastwrite)
        If retval = 0 Then
            keyname = Left(keyname, keylen)
            classname = Left(classname, classlen)
            DispName = GetSettingString(HKEY_LOCAL_MACHINE, _
"Software\Microsoft\Windows\CurrentVersion\Uninstall\" & keyname, _
"DisplayName")
            If DispName <> "" Then
                Debug.Print DispName
                'frmSWInstallato.List1.AddItem DispName
                    Write #1, DispName
                End If
            End If
            index = index + 1
        Wend
        retval = RegCloseKey(hKey)
        Close #1
    End Sub
</codice>
-- 
hth, hal


Grazie 1000 hal funziona alla perfezione :))) ora me lo studio un pò! 8P
Fabio