Ecco. La funzione che interessa è questa. Non interviene più il debugger perchè, come ho detto, ho eliminato a mano le cartelle a cui era negato l'accesso
codice:Public Sub ExtractAssociatedIconEx1() Try Dim folderName As String = Nothing If (Environment.GetCommandLineArgs.Length > 1) Then folderName = Environment.GetCommandLineArgs(1) End If ' Get the c:\ directory. If RadioButton1.Checked = True Then lstResults.Items.Clear() lstResults.LargeImageList = ImageList1 lstResults.SmallImageList = ImageList1 lstResults.View = View.List Dim dirInfo As DirectoryInfo Dim fileInfo As FileInfo Dim exeIcon As System.Drawing.Icon Dim sh As New NativeMethods.SHFILEINFO dirInfo = New DirectoryInfo("C:\Users\giorg\Documents\") For Each fileInfo In dirInfo.GetFiles("*" & TextBox1.Text & "*", SearchOption.AllDirectories) ImageList1.ColorDepth = ColorDepth.Depth32Bit sh = NativeMethods.GetInfoFromShell(fileInfo.FullName) If (Not String.IsNullOrEmpty(fileInfo.Extension)) Then exeIcon = CType(System.Drawing.Icon.FromHandle(sh.hIcon).Clone, Icon) ImageList1.ColorDepth = ColorDepth.Depth32Bit sh = NativeMethods.GetInfoFromShell(fileInfo.FullName) If (Not String.IsNullOrEmpty(fileInfo.Extension)) Then exeIcon = CType(System.Drawing.Icon.FromHandle(sh.hIcon).Clone, Icon) If (ImageList1.Images.ContainsKey(fileInfo.Name)) Then lstResults.Items.Add(fileInfo.FullName, fileInfo.FullName) ElseIf (Not exeIcon Is Nothing) Then ImageList1.Images.Add(fileInfo.FullName, exeIcon) lstResults.Items.Add(fileInfo.FullName, fileInfo.FullName) Else lstResults.Items.Add(fileInfo.FullName) End If End If End If Next Else lstResults.Items.Clear() lstResults.LargeImageList = ImageList1 lstResults.SmallImageList = ImageList1 lstResults.View = View.List Dim dirInfo As DirectoryInfo Dim fileInfo As FileInfo Dim exeIcon As System.Drawing.Icon Dim sh As New NativeMethods.SHFILEINFO dirInfo = New DirectoryInfo("C:\Users\giorg\Documents\") For Each fileInfo In dirInfo.GetFiles("*" & TextBox1.Text & "*", SearchOption.AllDirectories) ImageList1.ColorDepth = ColorDepth.Depth32Bit sh = NativeMethods.GetInfoFromShell(fileInfo.FullName) If (Not String.IsNullOrEmpty(fileInfo.Extension)) Then exeIcon = CType(System.Drawing.Icon.FromHandle(sh.hIcon).Clone, Icon) ImageList1.ColorDepth = ColorDepth.Depth32Bit sh = NativeMethods.GetInfoFromShell(fileInfo.FullName) If (Not String.IsNullOrEmpty(fileInfo.Extension)) Then exeIcon = CType(System.Drawing.Icon.FromHandle(sh.hIcon).Clone, Icon) If (ImageList1.Images.ContainsKey(fileInfo.Name)) Then lstResults.Items.Add(fileInfo.FullName, fileInfo.FullName) ElseIf (Not exeIcon Is Nothing) Then ImageList1.Images.Add(fileInfo.FullName, exeIcon) lstResults.Items.Add(fileInfo.FullName, fileInfo.FullName) Else lstResults.Items.Add(fileInfo.FullName) End If End If End If Next End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub

Rispondi quotando
