تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
طلب مساعدة في فهم كود wimgapi.dll
#1
السلام عليكم و رحمة الله و بركاته


إخواننا العباقرة في منتدانا الجميل منتدى فيجوال بيسك ، هذه أول مشاركة لي في هذا المنتدى الكبير و كنت أود من حضراتكم المساعدة في فهم كود معين
بحث عن كود للتعامل مع ملفات Windows image و التي تستخدم في أسطوانات ويندوز 7 و 8 عن طريق مكتبة مايكروسوفت wimgapi.dll
فوجدت كوداً عبارة عن class تجمع كل وظائف هذة المكتبة الرائعة و لكن لا أعرف كيف أستخدمها لأنها تحتاج إلى نوع من فك التشفير أو ما شابه ، فأرجو لمن يعرف من
حضراتكم هذا الكود و كيفية استخدمة يفيدنا و جزاكم الله خيراً ، و الكود كالآتي :
كود :
Imports System.Runtime.InteropServices
Imports System.Collections
Imports System.Globalization
Imports System.Text
Imports System.IO
Imports System.Xml
Imports System.IntPtr

Namespace WIMAPI
    Public Class WimApi
        <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
        Public Structure _WIM_INFO

            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
            Public WimPath As String
            Public Guid As Guid
            Public ImageCount As Int32
            Public CompressionType As Int32
            Public PartNumber As Int16
            Public TotalParts As Int16
            Public BootIndex As Int32
            Public WimAttributes As Int32
            Public WimFlagsAndAttr As Int32
        End Structure

        Public Structure _WIM_MOUNT_LIST
            Public WimPath As String
            Public MountPath As String
            Public ImageIndex As Int64
            Public MountedForRW As Int64
        End Structure

        Public Const WIM_DELETE_MOUNTS_ALL As UInteger = &H1
        Public Const WIM_GENERIC_READ As UInteger = &H80000000UI
        Public Const WIM_GENERIC_WRITE As UInteger = &H40000000
        Public Const WIM_CREATE_NEW As Integer = 1
        Public Const WIM_CREATE_ALWAYS As Integer = 2
        Public Const WIM_OPEN_EXISTING As Integer = 3
        Public Const WIM_OPEN_ALWAYS As Integer = 4
        Public Const WIM_COMPRESS_NONE As Integer = 0
        Public Const WIM_COMPRESS_XPRESS As Integer = 1
        Public Const WIM_COMPRESS_LZX As Integer = 2
        Public Const WIM_CREATED_NEW As Integer = 0
        Public Const WIM_OPENED_EXISTING As Integer = 1

        Public Const WIM_FLAG_RESERVED As Integer = &H1
        Public Const WIM_FLAG_VERIFY As Integer = &H2
        Public Const WIM_FLAG_INDEX As Integer = &H4
        Public Const WIM_FLAG_NO_APPLY As Integer = &H8
        Public Const WIM_FLAG_NO_DIRACL As Integer = &H10
        Public Const WIM_FLAG_NO_FILEACL As Integer = &H20
        Public Const WIM_FLAG_SHARE_WRITE As Integer = &H40
        Public Const WIM_FLAG_FILEINFO As Integer = &H80
        Public Const WIM_FLAG_NO_RP_FIX As Integer = &H100

        Public Const WIM_REFERENCE_APPEND As Integer = &H10000
        Public Const WIM_REFERENCE_REPLACE As Integer = &H20000

        ' WIMExportImage

        Public Const WIM_EXPORT_ALLOW_DUPLICATES As Integer = &H1
        Public Const WIM_EXPORT_ONLY_RESOURCES As Integer = &H2
        Public Const WIM_EXPORT_ONLY_METADATA As Integer = &H4

        ' WIMRegisterMessageCallback:

        Public Const INVALID_CALLBACK_VALUE As UInteger = &HFFFFFFFFUI

        Public Const WIM_COPY_FILE_RETRY As Integer = &H1000000
        Public Const COPY_FILE_FAIL_IF_EXISTS As Integer = &H1

        Public Const WM_APP As Integer = &H8000

        Public Const WIM_MSG As Integer = WM_APP + &H1476
        Public Const WIM_MSG_TEXT As Integer = WM_APP + &H1477
        Public Const WIM_MSG_PROGRESS As Integer = WM_APP + &H1478
        Public Const WIM_MSG_PROCESS As Integer = WM_APP + &H1479
        Public Const WIM_MSG_SCANNING As Integer = WM_APP + &H147A
        Public Const WIM_MSG_SETRANGE As Integer = WM_APP + &H147B
        Public Const WIM_MSG_SETPOS As Integer = WM_APP + &H147C
        Public Const WIM_MSG_STEPIT As Integer = WM_APP + &H147D
        Public Const WIM_MSG_COMPRESS As Integer = WM_APP + &H147E
        Public Const WIM_MSG_ERROR As Integer = WM_APP + &H147F
        Public Const WIM_MSG_ALIGNMENT As Integer = WM_APP + 1480
        Public Const WIM_MSG_RETRY As Integer = WM_APP + 1481
        Public Const WIM_MSG_SPLIT As Integer = WM_APP + 1482
        Public Const WIM_MSG_FILEINFO As Integer = WM_APP + 1483
        Public Const WIM_MSG_INFO As Integer = WM_APP + 1483
        Public Const WIM_MSG_WARNING As Integer = WM_APP + 1484
        Public Const WIM_MSG_CHK_PROCESS As Integer = WM_APP + 1485


        Public Const WIM_MSG_SUCCESS As Integer = &H0
        Public Const WIM_MSG_DONE As UInteger = &HFFFFFFF0UI
        Public Const WIM_MSG_SKIP_ERROR As UInteger = &HFFFFFFFEUI
        Public Const WIM_MSG_ABORT_IMAGE As UInteger = &HFFFFFFFFUI


        Public Const WIM_ATTRIBUTE_NORMAL As Integer = &H0
        Public Const WIM_ATTRIBUTE_RESOURCE_ONLY As Integer = &H1
        Public Const WIM_ATTRIBUTE_METADATA_ONLY As Integer = &H2
        Public Const WIM_ATTRIBUTE_VERIFY_DATA As Integer = &H4
        Public Const WIM_ATTRIBUTE_RP_FIX As Integer = &H8
        Public Const WIM_ATTRIBUTE_SPANNED As Integer = &H10
        Public Const WIM_ATTRIBUTE_READONLY As Integer = &H20

        Public Const WIM_XML_NODE_NAME As String = "NAME"
        Public Const WIM_XML_NODE_WIM As String = "WIM"
        Public Const WIM_XML_NODE_WINDOWS As String = "WINDOWS"
        Public Const WIM_XML_NODE_VERSION As String = "VERSION"
        Public Const WIM_XML_NODE_MAJOR As String = "MAJOR"
        Public Const WIM_XML_NODE_MINOR As String = "MINOR"
        Public Const WIM_XML_NODE_BUILD As String = "BUILD"
        Public Const WIM_XML_NODE_SPBUILD As String = "SPBUILD"

        '************************DllImport Attributes *********************************************
        '        * CallingConvention -  Specifies the calling convention to use in passing method arguments.*
        '        *                      The default is WinAPI, which corresponds to __stdcall               *
        '        *                      for the 32-bit Intel-based platforms.                               *
        '        * EntryPoint - Specifies the DLL entry point to be called.                                 *
        '        * SetLastError - Enables the caller to use the Marshal.GetLastWin32Error API               *
        '        *                function to determine whether an error occurred while                     *
        '        *                executing the method. In Visual Basic, the default is true;               *
        '        *                in C# and C++, the default is false.                                      *
        '        *******************************************************************************************


        ' WIMCreateFile  - Makes a new image file or opens an existing image file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMCreateFile", SetLastError:=True)> _
        Public Shared Function WIMCreateFile(<MarshalAs(UnmanagedType.LPWStr)> ByVal lpszWimPath As String, ByVal dwDesiredAccess As UInt32, ByVal dwCreationDisposition As Int32, ByVal dwFlagsAndAttributes As Int32, ByVal dwCompressionType As Int32, ByRef lpdwCreationResult As Int32) As IntPtr
        End Function

        ' WIMApplyImage  - Applies an image to a directory path from a Windows image (.wim) file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMApplyImage", SetLastError:=True)> _
        Public Shared Function WIMApplyImage(ByVal hImage As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszPath As String, ByVal dwApplyFlags As Int32) As Integer
        End Function

        ' WIMCaptureImage - Captures an image from a directory path and stores it in an image file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMCaptureImage", SetLastError:=True)> _
        Public Shared Function WIMCaptureImage(ByVal hWim As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszPath As String, ByVal dwApplyFlags As Int32) As IntPtr
        End Function

        ' WIMCloseHandle - Closes an open Windows Imaging (.wim) file or image handle.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMCloseHandle", SetLastError:=True)> _
        Public Shared Function WIMCloseHandle(ByVal hObject As IntPtr) As Integer
        End Function

        ' WIMDeleteImage - Removes an image from within a .wim (Windows image) file
        '                  so it cannot be accessed. However, the file resources
        '                  are still available for use by the WIMSetReferenceFile function.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMDeleteImage", SetLastError:=True)> _
        Public Shared Function WIMDeleteImage(ByVal hWim As IntPtr, ByVal dwApplyFlags As Int32) As Integer
        End Function

        ' WIMExportImage - Transfers the data of an image from one Windows image (.wim)
        '                  file to another.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMExportImage", SetLastError:=True)> _
        Public Shared Function WIMExportImage(ByVal hImage As IntPtr, ByVal hWim As IntPtr, ByVal dwApplyFlags As Int32) As Integer
        End Function

        ' WIMGetAttributes - Returns the information about the .wim file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMGetAttributes", SetLastError:=True)> _
        Public Shared Function WIMGetAttributes(ByVal hWim As IntPtr, ByRef lpWimInfo As _WIM_INFO, ByVal cbWimInfo As Int32) As Integer
        End Function

        ' WIMGetImageCount - Returns the number of volume images stored in a Windows image (.wim) file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMGetImageCount", SetLastError:=True)> _
        Public Shared Function WIMGetImageCount(ByVal hwim As IntPtr) As Int32
        End Function

        ' WIMGetMessageCallbackCount - Returns the count of callback routines currently registered by the imaging library.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMGetMessagecallbackCount", SetLastError:=True)> _
        Public Shared Function WIMGetMessagecallbackCount(ByVal hwim As IntPtr) As Int32
        End Function

        ' WIMLoadImage - Loads a volume image from a Windows image (.wim) file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMLoadImage", SetLastError:=True)> _
        Public Shared Function WIMLoadImage(ByVal hwim As IntPtr, ByVal dwImageIndex As Int32) As IntPtr
        End Function

        ' WIMSetBootImage - Marks the image with the given image index as bootable.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMSetBootImage", SetLastError:=True)> _
        Public Shared Function WIMSetBootImage(ByVal hwim As IntPtr, ByVal dwImageIndex As Int32) As Integer
        End Function

        ' WIMSetReferenceFile - Enables the WIMApplyImage and WIMCaptureImage
        '                       functions to use alternate .wim files for file
        '                       resources. This can enable optimization of storage
        '                       when multiple images are captured with similar data.


        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMSetReferenceFile", SetLastError:=True)> _
        Public Shared Function WIMSetReferenceFile(ByVal hwim As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszPath As String, ByVal dwFlags As Int32) As Integer
        End Function

        ' WIMSplitFile - Enables a large Windows image (.wim) file to be split
        '                into smaller parts for replication or storage on smaller forms of media.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMSplitFile", SetLastError:=True)> _
        Public Shared Function WIMSplitFile(ByVal hwim As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszPartPath As String, ByRef pliPartSize As Int64, ByVal dwFlags As Int32) As Integer
        End Function

        ' WIMMountImage - Mounts an image in a Windows image (.wim) file to the specified directory.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMMountImage", SetLastError:=True)> _
        Public Shared Function WIMMountImage(<MarshalAs(UnmanagedType.LPWStr)> ByVal lpszMountPath As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszWimFileName As String, ByVal dwImageIndex As Int32, <[Optional]()> <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszTempPath As String) As Boolean
        End Function

        ' WIMUnmountImage - Unmounts a mounted image in a Windows image (.wim)
        '                   file from the specified directory.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMUnmountImage", SetLastError:=True)> _
        Public Shared Function WIMUnmountImage(<MarshalAs(UnmanagedType.LPWStr)> ByVal lpszMountPath As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszWimFileName As String, ByVal dwImageIndex As Int32, ByVal bCommitChanges As Integer) As Integer
        End Function

        ' WIMSetTemporaryPath - Sets the location where temporary imaging files
        '                       are to be stored.


        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMSetTemporaryPath", SetLastError:=True)> _
        Public Shared Function WIMSetTemporaryPath(ByVal hWim As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszPath As String) As Integer
        End Function

        ' WIMCopyFile - Copies an existing file to a new file. Notifies the
        '               application of its progress through a callback function.
        '               If the source file has verification data, the contents of
        '               the file are verified during the copy operation.


        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMCopyFile", SetLastError:=True)> _
        Public Shared Function WIMCopyFile(<MarshalAs(UnmanagedType.LPWStr)> ByVal lpszExistingFileName As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpszNewFileName As String, ByVal lpProgressRoutine As CopyProgressRoutine, ByVal lpvData As IntPtr, ByRef pbCancel As Int32, ByVal dwCopyFlags As Int32) As Integer
        End Function

        ' WIMRegisterMessageCallback - Registers a function to be called with imaging-specific data.
        '                              For information about the messages that can be handled,
        '                              see Messages

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMRegisterMessageCallback", SetLastError:=True)> _
        Public Shared Function WIMRegisterMessageCallback(ByVal hwim As IntPtr, ByVal fpMessageProc As WIMMessageCallback, ByVal lpvUserData As IntPtr) As Int32
        End Function

        ' WIMUnregisterMessageCallback - Unregisters a function from being called with imaging-specific data.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMUnregisterMessageCallback", SetLastError:=True)> _
        Public Shared Function WIMUnregisterMessageCallback(ByVal hwim As IntPtr, ByVal fpMessageProc As WIMMessageCallback) As Long
        End Function

        ' WIMGetImageInformation - Returns information about an image within the .wim (Windows image) file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMGetImageInformation", SetLastError:=True)> _
        Public Shared Function WIMGetImageInformation(ByVal hImage As IntPtr, ByRef lplpvImageInfo As IntPtr, ByRef lpcbImageInfo As Int32) As Int32
        End Function


        <DllImport("kernel32.dll", EntryPoint:="LocalFree", SetLastError:=True)> _
        Public Shared Function LocalFree(ByVal hMem As IntPtr) As Long
        End Function

        ' WIMSetImageInformation - Stores information about an image in the Windows image (.wim) file.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMSetImageInformation", SetLastError:=True)> _
        Public Shared Function WIMSetImageInformation(ByVal hImage As IntPtr, ByVal lpvImageInfo As IntPtr, ByVal cbImageInfo As Integer) As Integer
        End Function

        ' WIMDeleteImageMounts - Removes images from all directories where they have been previously mounted.

        <DllImport("tools\wimgapi.dll", EntryPoint:="WIMDeleteImageMounts", SetLastError:=True)> _
        Public Shared Function WIMDeleteImageMounts(ByVal Flag As Integer) As Integer
        End Function

        Public Delegate Function CopyProgressRoutine(ByVal TotalFileSize As Long, ByVal TotalBytesTransferred As Long, ByVal StreamSize As Long, ByVal StreamBytesTransferred As Long, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, _
         ByVal hSourceFile As Integer, ByVal hDestinationFile As Integer, ByVal lpData As Integer) As Long

        ' WIMMessageCallback - An application-defined function used with the
        '                      WIMRegisterMessageCallback or WIMUnregisterMessageCallback functions.

        Public Delegate Function WIMMessageCallback(ByVal dwMessageId As Int32, ByVal wParam As Int32, ByVal lParam As Int32, ByVal lpvUserData As Int32) As Int32

        ' Get the Name for the given Image in the WIM file
        ' if image not found, returns blank string

        Public Shared Function GetNameForImage(ByVal WimFileName As String, ByVal ImageIndex As Integer) As String
            Dim strReturn As String = ""
            Dim xmlImageData As New XmlDocument()
            Dim hWIM As IntPtr
            Dim XMLInfo As IntPtr = CType(0, IntPtr)
            Dim iLength As Int32 = 0
            Dim iReturn As Int32

            Dim created As Integer
            hWIM = WIMCreateFile(WimFileName, WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, WIM_COMPRESS_XPRESS, created)

            If hWIM Then
                iReturn = WIMGetImageInformation(hWIM, XMLInfo, iLength)

                If iReturn <> 0 Then
                    Dim XMLStr As [String] = Marshal.PtrToStringUni(XMLInfo)
                    Dim EditedXML As [String] = XMLStr.Substring(1)
                    xmlImageData.LoadXml(EditedXML)
                    Dim root As XmlNode = xmlImageData.DocumentElement
                    If root.Name = WimApi.WIM_XML_NODE_WIM Then
                        Dim xmlImage As XmlNode = root.LastChild
                        Dim icount As Integer = root.ChildNodes.Count
                        For i As Integer = 1 To icount - 1
                            If i = ImageIndex Then
                                Dim ichild As Integer = xmlImage.ChildNodes.Count
                                If ichild > 0 Then
                                    For j As Integer = 0 To ichild - 1
                                        If xmlImage.ChildNodes(j).Name = (WIM_XML_NODE_NAME) Then
                                            strReturn = xmlImage.ChildNodes(j).InnerText
                                        End If
                                    Next
                                End If
                            End If

                        Next
                    End If
                End If
                WIMCloseHandle(hWIM)
            End If
            Return strReturn
        End Function

        ' Get the name for the image, if given the WIM file name and ImageID
        ' If image not found, returns 0

        Public Shared Function GetIDForImage(ByVal strWimFileName As String, ByVal Imagename As String) As Integer
            Dim iID As Integer = 0
            Dim xmlImageData As New XmlDocument()
            Dim hWIM As IntPtr
            Dim XMLInfo As IntPtr = CType(0, IntPtr)
            Dim iLength As Int32 = 0
            Dim iReturn As Int32
            Dim strName As String = Imagename.ToUpper()
            Dim created As Integer
            hWIM = WIMCreateFile(strWimFileName, WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, WIM_COMPRESS_XPRESS, created)


            If hWIM Then
                iReturn = WIMGetImageInformation(hWIM, XMLInfo, iLength)

                If iReturn <> 0 Then
                    Dim XMLStr As [String] = Marshal.PtrToStringUni(XMLInfo)
                    Dim EditedXML As [String] = XMLStr.Substring(1)
                    xmlImageData.LoadXml(EditedXML)
                    Dim root As XmlNode = xmlImageData.DocumentElement
                    If root.Name = WimApi.WIM_XML_NODE_WIM Then
                        Dim xmlImage As XmlNode = root.LastChild
                        Dim icount As Integer = root.ChildNodes.Count
                        For i As Integer = 1 To icount - 1
                            Dim ichild As Integer = xmlImage.ChildNodes.Count
                            If ichild > 0 Then
                                For j As Integer = 0 To ichild - 1
                                    If xmlImage.ChildNodes(j).Name = WIM_XML_NODE_NAME Then
                                        If xmlImage.ChildNodes(j).InnerText.ToUpper() = strName Then
                                            iID = i
                                        End If
                                    End If
                                Next
                            End If
                        Next

                    End If
                End If
                WIMCloseHandle(hWIM)
            End If
            Return iID
        End Function

        ' Get the list of all Imagenames in the given WIM file
        ' Returns a string in the format n1-name1;n2-name2;  etc

        Public Shared Function GetImageNames(ByVal strWimFileName As String) As String
            Dim strReturn As String = ""
            Dim xmlImageData As New XmlDocument()
            Dim hWIM As IntPtr
            Dim XMLInfo As IntPtr = CType(0, IntPtr)
            Dim iLength As Int32 = 0
            Dim iReturn As Int32

            Dim created As Integer
            hWIM = WIMCreateFile(strWimFileName, WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, WIM_COMPRESS_XPRESS, created)


            If hWIM Then
                iReturn = WIMGetImageInformation(hWIM, XMLInfo, iLength)

                If iReturn <> 0 Then
                    Dim XMLStr As [String] = Marshal.PtrToStringUni(XMLInfo)
                    Dim EditedXML As [String] = XMLStr.Substring(1)
                    xmlImageData.LoadXml(EditedXML)
                    Dim root As XmlNode = xmlImageData.DocumentElement
                    If root.Name = WimApi.WIM_XML_NODE_WIM Then
                        Dim xmlImage As XmlNode = root.LastChild
                        Dim icount As Integer = root.ChildNodes.Count
                        For i As Integer = 1 To icount - 1
                            Dim ichild As Integer = xmlImage.ChildNodes.Count
                            If ichild > 0 Then
                                For j As Integer = 0 To ichild - 1
                                    If xmlImage.ChildNodes(j).Name = WIM_XML_NODE_NAME Then
                                        'strReturn += i.ToString() + "-";
                                        strReturn += xmlImage.ChildNodes(j).InnerText
                                        strReturn += ";"
                                    End If
                                Next
                            End If
                        Next
                    End If
                End If
                WIMCloseHandle(hWIM)
            End If

            Return strReturn
        End Function


        '''<summary>
        '''Mounts an image in a .wim file to the specified directory.
        '''</summary>
        '''<returns>Returns TRUE and sets the LastError to ERROR_SUCCESS.
        '''Returns FALSE in case of a failure and the LastError is set to the appropriate Win32 error value.
        '''</returns>
        Public Shared Sub MountImage(ByVal mountPath As String, ByVal windowsImageFileName As String, ByVal imageIndex As Integer)
            Dim status As Boolean = False
            Dim rc As Integer

            Try
                status = WIMMountImage(mountPath, windowsImageFileName, imageIndex, System.Environment.GetEnvironmentVariable("temp"))
                rc = Marshal.GetLastWin32Error()
            Catch generatedExceptionName As System.StackOverflowException
                '
                'Throw an exception.
                '
                Throw New System.InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Unable to mount image {0} to {1}.", windowsImageFileName, mountPath))
            End Try
            If status = False Then
                '
                'Throw an exception.
                '
                Throw New System.InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Unable to mount image {0} to {1}. Error = {2}", windowsImageFileName, mountPath, rc))
            End If
        End Sub


    End Class

    ' UTILTY Class to get all needed infoirmation about an Image in a WIM file
    ' constructor takes the WIM File name and the image id as parameters
    ' Usually get the image count in the WIM file and instantiate as many CFIWIMImage
    ' objects as per the number of images in the WIM file
    ' IF THE OBJECT IS NOT CONSTRUCTED , iSuccess is set to false.

    Public Class WindowsImage
        Private m_WimPath As String

        Public ReadOnly Property WimPath() As String
            Get
                Return m_WimPath
            End Get
        End Property
        Private m_ImageID As Integer
        Public ReadOnly Property ImageID() As Integer
            Get
                Return m_ImageID
            End Get
        End Property
        Private m_ImageName As String
        Public ReadOnly Property ImageName() As String
            Get
                Return m_ImageName
            End Get
        End Property
        Private m_Major As Int32
        Public ReadOnly Property Major() As Int32
            Get
                Return m_Major
            End Get
        End Property
        Private m_Minor As Int32
        Public ReadOnly Property Minor() As Int32
            Get
                Return m_Minor
            End Get
        End Property
        Private m_Build As Int32
        Public ReadOnly Property Build() As Int32
            Get
                Return m_Build
            End Get
        End Property
        Private m_SPBuild As Int32
        Public ReadOnly Property SPBuild() As Int32
            Get
                Return m_SPBuild
            End Get
        End Property
        Private m_Success As Boolean
        Public ReadOnly Property Success() As Boolean
            Get
                Return m_Success
            End Get
        End Property

        Public Sub New(ByVal wimfile As String, ByVal index As Integer)
            m_WimPath = wimfile
            m_ImageID = index
            Dim hWim As IntPtr
            Dim created As Integer
            Dim XMLInfo As IntPtr = CType(0, IntPtr)
            Dim iLength As Int32 = 0
            Dim iReturn As Integer
            m_Success = False

            hWim = WimApi.WIMCreateFile(wimfile, WimApi.WIM_GENERIC_READ, WimApi.WIM_OPEN_EXISTING, WimApi.WIM_FLAG_VERIFY, WimApi.WIM_COMPRESS_XPRESS, created)

            If hWim Then
                iReturn = WimApi.WIMGetImageInformation(hWim, XMLInfo, iLength)

                If iReturn <> 0 Then
                    Dim xmlImageData As New XmlDocument()
                    Dim XMLStr As [String] = Marshal.PtrToStringUni(XMLInfo)
                    Dim EditedXML As [String] = XMLStr.Substring(1)
                    xmlImageData.LoadXml(EditedXML)
                    Dim root As XmlNode = xmlImageData.DocumentElement
                    If root.Name = WimApi.WIM_XML_NODE_WIM Then
                        Dim xmlImage As XmlNode = root.LastChild
                        Dim icount As Integer = root.ChildNodes.Count
                        For i As Integer = 1 To icount - 1
                            If i = index Then
                                m_Success = True
                                Dim ichild As Integer = xmlImage.ChildNodes.Count
                                If ichild > 0 Then
                                    For j As Integer = 0 To ichild - 1
                                        If xmlImage.ChildNodes(j).Name = WimApi.WIM_XML_NODE_NAME Then
                                            m_ImageName = xmlImage.ChildNodes(j).InnerText
                                        End If
                                        If xmlImage.ChildNodes(j).Name = WimApi.WIM_XML_NODE_WINDOWS Then

                                            Dim xmlWindows As XmlNode = xmlImage.ChildNodes(j)
                                            Dim iWCount As Integer = xmlWindows.ChildNodes.Count
                                            For ij As Integer = 0 To iWCount - 1
                                                If xmlWindows.ChildNodes(ij).Name = WimApi.WIM_XML_NODE_VERSION Then
                                                    Dim xmlVersion As XmlNode = xmlWindows.ChildNodes(ij)
                                                    Dim iVCount As Integer = xmlVersion.ChildNodes.Count
                                                    For k As Integer = 0 To iVCount - 1
                                                        If xmlVersion.ChildNodes(k).Name = WimApi.WIM_XML_NODE_MAJOR Then
                                                            m_Major = Convert.ToInt32(xmlVersion.ChildNodes(k).InnerText)
                                                        End If
                                                        If xmlVersion.ChildNodes(k).Name = WimApi.WIM_XML_NODE_MINOR Then
                                                            m_Minor = Convert.ToInt32(xmlVersion.ChildNodes(k).InnerText)
                                                        End If
                                                        If xmlVersion.ChildNodes(k).Name = WimApi.WIM_XML_NODE_BUILD Then
                                                            m_Build = Convert.ToInt32(xmlVersion.ChildNodes(k).InnerText)
                                                        End If
                                                        If xmlVersion.ChildNodes(k).Name = WimApi.WIM_XML_NODE_SPBUILD Then
                                                            m_SPBuild = Convert.ToInt32(xmlVersion.ChildNodes(k).InnerText)
                                                        End If
                                                    Next
                                                End If
                                            Next
                                        End If
                                    Next
                                End If
                            End If
                        Next
                    End If
                End If

                WimApi.WIMCloseHandle(hWim)
            End If
        End Sub

    End Class

End Namespace
الرد }}}
تم الشكر بواسطة:
#2
من اين اتيت بهذه الفئة ؟؟
الرد }}}
تم الشكر بواسطة:
#3
من أحد المواقع الأجنبية
الرد }}}
تم الشكر بواسطة:
#4
هذة الفئة تعمل بنظام Api و لكن هو يحتاج إلى بعض الشيفرات أنا جربت بعض الأكواد فية و إشتغلت
الرد }}}
تم الشكر بواسطة:
#5
اي شيفرات . كل مااراه هو دوال api ودوال عادية وجمل تكرار loop
الرد }}}
تم الشكر بواسطة:
#6
أقصد لو أن حضرتك أردت استخدام كود مثل
wimapi.WIMGetAttributes
سيطلب كتابة بين قوسين المفروض مكان ملف wim لكنه سيطلبه بصورة system.intptr هذا ما أقصد
فكيف أحول مسار مثل C:\install.Wim إلى تلك الصيغة الرقمية؟؟
الرد }}}
تم الشكر بواسطة:
#7
Mstrano كتب :أقصد لو أن حضرتك أردت استخدام كود مثل
wimapi.WIMGetAttributes
سيطلب كتابة بين قوسين المفؤوض مكان ملف wim لكنه سيطلبه بصورة system.intptr هذا ما أقصد
فكيف أحول مسار مثل C:\install.Wim إلى تلك الصيغة الرقمية؟؟

مستحيل

وظيفة intptr ليس لتحويل المسارات

انما هذا نوع من البيانات يستخدم للتعامل مع عناوين الكائنات(handle) كنوافذ البرامج وازرارها


انا لحد الان ما فهمت ويش ده windows image

هل هو سيدي الوندوز ؟؟
الرد }}}
تم الشكر بواسطة:
#8
أنا فقط أحاول استخدام هذه الأداة للتعامل مع ملفات wim و مبرمج الفئة وضع بعض الأشياء فيها مثل
WIMGetImageCount(ByVal hwim As IntPtr) As Int32
كهذا .... استخدمت قبلا أداة imagex و كانت لتفعل ذلك الأمر لابد من معرفة أولا مكان ملف wim و هو string و فكيف يستعاض عنه بالهاندل
الرد }}}
تم الشكر بواسطة:
#9
Mstrano كتب :أنا فقط أحاول استخدام هذه الأداة للتعامل مع ملفات wim و مبرمج الفئة وضع بعض الأشياء فيها مثل
WIMGetImageCount(ByVal hwim As IntPtr) As Int32
كهذا .... استخدمت قبلا أداة imagex و كانت لتفعل ذلك الأمر لابد من معرفة أولا مكان ملف wim و هو string و فكيف يستعاض عنه بالهاندل

اعتقد اني قرات عن ذلك مسبقا وهو جلب handle من filestream بس ذاكرتي مشوشة شوي

ثواني ابحث لك
الرد }}}
تم الشكر بواسطة:
#10
قمت بالعبث في فئة filestream وبالفعل هناك طريقة لجلب handle للفايل

هذا نوع جديد من الhandle لم اكن اعلم بوجوده انا كان خبري ان الهاندل فقط رقم يشير ل الواجهات والعناصر

ولكن هناك مايسمى ب file handle

انا كتبت الكود لكن طلع تحذير يقولي عليك ان تحول شيئ اولا

بكمل الكود وبرد عليك
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [VB.NET] مساعدة في تقرير mrfenix93 1 41 24-03-24, 10:29 PM
آخر رد: mrfenix93
  مساعدة jalaltech 1 95 07-03-24, 07:38 PM
آخر رد: قناص المدينة
  [VB.NET] مساعدة فى كود فاتورة اللكترونية asdfar1977 2 194 02-03-24, 02:00 AM
آخر رد: asdfar1977
  مساعدة فى كود فاتورة الكترونية asdfar1977 0 79 29-02-24, 07:14 PM
آخر رد: asdfar1977
  مساعدة jalaltech 0 133 17-02-24, 02:15 AM
آخر رد: jalaltech
  طلب مساعدة AHMED213 3 323 06-02-24, 09:39 PM
آخر رد: AHMED213
  [VB.NET] طلب مساعدة AHMED213 0 220 31-01-24, 12:56 AM
آخر رد: AHMED213
  طلب مساعدة بخصوص كود الطباعة paveldida 2 461 19-01-24, 12:00 AM
آخر رد: العتيق
  [VB.NET] مساعدة في استدعاء البيانات معينه من form الأول إلى form 2 بدون التعديل loay775 2 274 18-01-24, 05:04 PM
آخر رد: loay775
  اريد مساعدة في العملية الحسابية melad2002 3 406 29-12-23, 09:10 PM
آخر رد: melad2002

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


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