منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : تعديل هذا الكود
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
كود :
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Management

Public Class icoExtractor

    Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef newHandle As IntPtr, ByVal cbFileInfo As Integer, ByVal uFlagsn As Integer) As Integer

    Private Structure icoInfo
        Public iconPath As String 'self explanatory, path of the process (where to get the icon)
        Public processName As String 'again, obvious, process name. herp derp.
        Public Sub New(ByVal i As String, ByVal p As String)
            Me.iconPath = i
            Me.processName = p
        End Sub
    End Structure

    Private Function getIcon(ByVal processPath As String) As Image
        Dim icoHandle As IntPtr = IntPtr.Zero 'create the variable to hold the handle, will be passed ByRef to the API and the actual handle will result.
        Dim flags As Integer = &H100 Or &H10 Or &H1 'set the flags, basically says it's an icon, it's a small icon and some file shit
        SHGetFileInfo(processPath, 256, icoHandle, 0, flags) 'API call, will point to our icon.
        Dim ico As Icon = Icon.FromHandle(icoHandle) 'extract the icon from the handle.
        Return ico.ToBitmap 'return the icon.
    End Function

    Public Shared Function getProcessIcons(ByVal processList As Process()) As ImageList
        Dim procNames As String() = processList.Select(Function(p As Process) p.ProcessName).ToArray 'get the names of the processes in the list
        Dim output As New ImageList 'create the imagelist we'll return.
        Dim tempExtractor As New icoExtractor 'create an instance of the icoExtractor class to access the private methods.
        Dim pList As List(Of icoInfo) = tempExtractor.getPaths(procNames) 'get the icon paths of all the processes.
        For Each p As icoInfo In pList 'loop through the iconInfo of each entry.
            If Not output.Images.ContainsKey(p.processName) Then output.Images.Add(p.processName, tempExtractor.getIcon(p.iconPath)) 'check if the imagelist contains the key, if not add the icon to the list.
        Next
        Return output 'return the imagelist.
    End Function
    Private Function getPaths(ByVal procNames As String()) As List(Of icoInfo)
        Dim pList As New List(Of icoInfo) 'the output variable.
        Using searcher As New ManagementObjectSearcher("root\CIMV2", "select * from Win32_Process") 'query the root\CIMV2 path, with the select * from Win32_Process query, will return info on every process.
            Using iterator As ManagementObjectCollection.ManagementObjectEnumerator = searcher.Get.GetEnumerator 'get the Enumerator to step through each object that the query returned
                While iterator.MoveNext 'while there is still more processes...
                    Dim name As String = IO.Path.GetFileNameWithoutExtension(iterator.Current("name").ToString) 'use the IO.Path class to remove and extensions from the process name (.exe etc)
                    If procNames.Contains(Name) AndAlso iterator.Current("ExecutablePath") IsNot Nothing Then 'if the original process list contains this process, and it has an executable path...
                        pList.Add(New icoInfo(iterator.Current("ExecutablePath").ToString, name)) 'add it to the icoInfo list
                    End If
                End While
            End Using 'dispose the Enumerator
        End Using 'dispose the ObjectSearcher
        Return pList 'return the list of icoInfo.
    End Function
End Class
الخطئ فى هذا السطر
كود :
Using searcher As New ManagementObjectSearcher("root\CIMV2", "select * from Win32_Process")
وضح طلبك بالتحديد ما ذا تريد ان تعرف من معلومات للجهاز ؟