تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تعديل هذا الكود
#1
كود :
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")
الرد }}}}
تم الشكر بواسطة:
#2
وضح طلبك بالتحديد ما ذا تريد ان تعرف من معلومات للجهاز ؟
الرد }}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  ممكن شرح هذا الكود؟ rafaag777 1 91 منذ 8 ساعة مضت
آخر رد: الماجيك مسعد
  ما الخطأ فى هذا الكود ؟ what's error in my code ? twitter acount creator الماجيك مسعد 0 21 منذ 8 ساعة مضت
آخر رد: الماجيك مسعد
  حل مشكلة الكود الاتي - سهل- CLARO 3 89 02-12-16, 04:06 PM
آخر رد: ali.alfoly
  [كود] تعديل كود البحث بين تاريخينب hglogtd 2 44 29-11-16, 01:37 AM
آخر رد: hglogtd
  ما هو الخطاء فى هذا الكود "كود التعديل" السيد الجوهري 1 65 26-11-16, 03:22 AM
آخر رد: أبو عمر
  [VB.NET] ربط الداتا بيز بالكريستال ريبورت عن طريق الكود thevirus 3 99 22-11-16, 02:38 PM
آخر رد: thevirus
  [VB.NET] طلب تعديل ع الكود ليصبح البرنامج جاهزاً 3asfa~mdmra 8 202 12-11-16, 02:30 AM
آخر رد: 3asfa~mdmra
  [سؤال] هل يمكن عرض عناصر الكومبوبوكس عن طريق الكود ؟؟؟؟؟؟؟؟؟؟؟؟ thevirus 1 104 10-11-16, 06:25 PM
آخر رد: أبو عمر
  كيف اضيف هذا الكود في module nabil.1710 6 128 01-11-16, 03:23 PM
آخر رد: silverlight
  كيف انقل هذا الكود منForm2 اليForm1 3asfa~mdmra 2 77 30-10-16, 01:47 PM
آخر رد: 3asfa~mdmra

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم