|
8#
楼主 |
发表于 2009-6-28 17:16:54
|
只看该作者
MWim.VB:- Imports System.Runtime.InteropServices
- Imports System.IO
- Module MWim
- Public Const WIM_GENERIC_READ As Long = &H80000000
- Public Const WIM_GENERIC_WRITE As Long = &H40000000
- Public Const WIM_CREATE_NEW As Byte = &H1
- Public Const WIM_CREATE_ALWAYS As Byte = &H2
- Public Const WIM_OPEN_EXISTING As Byte = &H3
- Public Const WIM_OPEN_ALWAYS As Byte = &H4
- Public Const WIM_COMPRESS_NONE As Byte = 0
- Public Const WIM_COMPRESS_XPRESS As Byte = 1
- Public Const WIM_COMPRESS_LZX As Byte = 2
- Public Const WIM_CREATED_NEW As Byte = 0
- Public Const WIM_OPENED_EXISTING As Byte = 1
- Public Const WIM_FLAG_RESERVED As Byte = &H1
- Public Const WIM_FLAG_VERIFY As Byte = &H2
- Public Const WIM_FLAG_INDEX As Byte = &H4
- Public Const WIM_FLAG_NO_APPLY As Byte = &H8
- Public Const WIM_FLAG_NO_DIRACL As Byte = &H10
- Public Const WIM_FLAG_NO_FILEACL As Byte = &H20
- Public Const WIM_FLAG_SHARE_WRITE As Byte = &H40
- Public Const WIM_FLAG_FILEINFO As Byte = &H80
- Public Const WIM_FLAG_NO_RP_FIX As Integer = &H100
- Public Const WIM_REFERENCE_APPEND As Long = &H10000
- Public Const WIM_REFERENCE_REPLACE As Long = &H20000
- Public Const WIM_EXPORT_ALLOW_DUPLICATES As Byte = &H1
- Public Const WIM_EXPORT_ONLY_RESOURCES As Byte = &H2
- Public Const WIM_EXPORT_ONLY_METADATA As Byte = &H4
- Public Const INVALID_CALLBACK_VALUE As Long = &HFFFFFFFF
- Public Const WIM_COPY_FILE_RETRY As Long = &H1000000
- Public Const WIM_MSG_SUCCESS As Byte = 0&
- Public Const WIM_MSG_DONE As Long = &HFFFFFFF0
- Public Const WIM_MSG_SKIP_ERROR As Long = &HFFFFFFFE
- Public Const WIM_MSG_ABORT_IMAGE As Long = &HFFFFFFFF
- Public Const WIM_ATTRIBUTE_NORMAL As Byte = &H0
- Public Const WIM_ATTRIBUTE_RESOURCE_ONLY As Byte = &H1
- Public Const WIM_ATTRIBUTE_METADATA_ONLY As Byte = &H2
- Public Const WIM_ATTRIBUTE_VERIFY_DATA As Byte = &H4
- Public Const WIM_ATTRIBUTE_RP_FIX As Byte = &H8
- Public Const WIM_ATTRIBUTE_SPANNED As Byte = &H10
- Public Const WIM_ATTRIBUTE_READONLY As Byte = &H20
- Private Declare Auto Function WIMCreateFile Lib "wimgapi.dll" (<MarshalAs(UnmanagedType.LPWStr)> ByVal WIMPath As String, ByVal AccessType As Integer, ByVal Creation As UInt32, ByVal Flags As UInt32, ByVal Compression As UInt32, ByRef CreationResult As Integer) As IntPtr
- Private Declare Auto Function WIMMountImage Lib "wimgapi.dll" (ByVal eMountPath As String, ByVal eWimFile As String, ByVal eIndex As Integer, Optional ByVal eTempPath As String = "C:\Windows\Temp") As Boolean
- Private Declare Auto Function WIMGetImageInformation Lib "wimgapi.dll" (ByVal hWnd As IntPtr, ByRef ImageInfo As IntPtr, ByRef ImageInfoSize As IntPtr) As Boolean
- Private Declare Auto Function WIMUnmountImage Lib "wimgapi.dll" (ByVal MountPath As String, ByVal WimFile As String, ByVal Index As Integer, ByVal CommitChanges As Boolean) As Boolean
- Private Declare Auto Function WIMDeleteImage Lib "wimgapi.dll" (ByVal hWim As IntPtr, ByVal dwApplyFlags As Integer) As Boolean
- Private Declare Function WIMSplitFile Lib "WIMGAPI.DLL" (ByVal hwim As Long, ByVal lpszPartPath As String, ByRef pliPartSize As Integer, ByVal dwFlags As Integer) As Boolean
- Private Declare Function WIMCaptureImage Lib "WIMGAPI.DLL" (ByVal hwim As Long, ByVal lpszPath As String, ByVal dwCaptureFlags As Long) As Boolean
- Private Declare Function WIMSetImageInformation Lib "WIMGAPI.DLL" (ByVal hImage As Long, ByVal lpvImageInfo As Long, ByVal cbImageInfo As Integer) As Boolean
- Private Declare Auto Function WIMCloseHandle Lib "wimgapi.dll" (ByVal Handle As IntPtr) As Boolean
- Private Declare Auto Function WIMSetTemporaryPath Lib "wimgapi.dll" (ByVal hWnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal TemporaryPath As String) As Boolean
- Private Declare Function WIMExportImage Lib "wimgapi.dll" (ByVal hImage As IntPtr, ByVal hWim As IntPtr, ByVal dwApplyFlags As Integer) As Boolean
- Private Declare Function WIMLoadImage Lib "wimgapi.dll" (ByVal hwim As IntPtr, ByVal dwImageIndex As Integer) As IntPtr
- Public Sub DeleteFolder(ByVal Folder As String, ByVal Recreate As Boolean)
- Try
- Do Until Not Directory.Exists(Folder)
- Directory.Delete(Folder, True)
- Loop
- Catch
- End Try
- Try
- If Recreate = True Then Directory.CreateDirectory(Folder)
- Catch
- End Try
- End Sub
- Public Function CWIM_MountImage(ByVal Index As Integer, ByVal WIMFile As String, ByVal MountPath As String)
- DeleteFolder(MountPath, True)
- Dim Mounted As Boolean = False
- Try
- WIMMountImage(MountPath, WIMFile, Index)
- If Directory.Exists(MountPath & "\Windows") Then
- Mounted = True
- Else
- Mounted = False
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- Mounted = False
- End Try
- Return Mounted
- End Function
- Public Function CWIM_UnmountImage(ByVal Index As Integer, ByVal WimFile As String, ByVal MountPath As String, Optional ByVal Save As Boolean = False)
- Dim Unmounted As Boolean = False
- Try
- WIMUnmountImage(MountPath, WimFile, Index, Save)
- If Not Directory.Exists(MountPath & "\Windows") Then
- Unmounted = True
- DeleteFolder(MountPath, False)
- Else
- Unmounted = False
- End If
- Catch
- Unmounted = False
- End Try
- Return Unmounted
- End Function
- Public Sub CWIM_DeleteImage(ByVal WIMFile As String, ByVal Index As Integer)
- Dim lHandle As IntPtr = WIMCreateFile(WIMFile, WIM_GENERIC_WRITE, WIM_OPEN_EXISTING, WIM_FLAG_SHARE_WRITE, WIM_COMPRESS_XPRESS, 0)
- WIMSetTemporaryPath(lHandle, "C:\Windows\Temp")
- WIMDeleteImage(lHandle, Index)
- WIMCloseHandle(lHandle)
- End Sub
- Public Function CWIM_GetWimInfo(ByVal WimImg As String)
- Dim s As IntPtr = WIMCreateFile(WimImg, WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, WIM_COMPRESS_NONE, WIM_OPENED_EXISTING)
- Dim XMLInf, iSize As IntPtr
- WIMGetImageInformation(s, XMLInf, iSize)
- Dim XMLStr = System.Runtime.InteropServices.Marshal.PtrToStringUni(XMLInf)
- WIMCloseHandle(s)
- Return XMLStr.Substring(1)
- End Function
- Public Sub CWIM_CaptureImage(ByVal Folder As String, ByVal WimImg As String, ByVal Compression As Long, ByVal TempFolder As String)
- DeleteFolder(TempFolder, True)
- Dim lHandle As IntPtr = WIMCreateFile(WimImg, WIM_GENERIC_WRITE, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, Compression, WIM_CREATED_NEW)
- WIMSetTemporaryPath(lHandle, TempFolder)
- WIMCaptureImage(lHandle, Folder, Compression)
- WIMCloseHandle(lHandle)
- End Sub
- Public Sub CWIM_ExportImage(ByVal OriginalWIm As String, ByVal NewWIM As String, ByVal sIndex As Integer, ByVal Temp As String)
- DeleteFolder(Temp, True)
- Dim s As IntPtr = WIMCreateFile(OriginalWIm, WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, WIM_COMPRESS_NONE, WIM_OPENED_EXISTING)
- Dim t As IntPtr = WIMCreateFile(NewWIM, WIM_GENERIC_WRITE, WIM_OPEN_ALWAYS, WIM_FLAG_VERIFY, WIM_COMPRESS_XPRESS, WIM_CREATED_NEW)
- WIMSetTemporaryPath(t, Temp)
- WIMSetTemporaryPath(s, Temp)
- Dim si As IntPtr = WIMLoadImage(s, sIndex)
- WIMExportImage(si, t, 0)
- WIMCloseHandle(si)
- WIMCloseHandle(t)
- WIMCloseHandle(s)
- DeleteFolder(Temp, False)
- End Sub
- End Module
复制代码 淘了一个下午从国外论坛淘回来的
测试通过 : )
简陋示例见附件
反正我需要的只是第一个卷的信息
[ 本帖最后由 neo4026 于 2009-6-28 17:33 编辑 ] |
|