konganjie
konganjie
2019-01-12 22:41

WIMGAPI的WIMApplyImage相关问题(VB.net),求大神帮忙看看

在vb.net中调用WIMGAPI.DLL
WIMExportImage 没有问题

Private Declare Function WIMExportImage Lib "wimgapi.dll" (ByVal hImage As IntPtr, ByVal hWim As IntPtr, ByVal dwApplyFlags As Integer) As Boolean

Private Declare Auto Function WIMSetTemporaryPath Lib "wimgapi.dll" (ByVal hWnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal TemporaryPath As String) As Boolean

Public Sub S_ExportImage(ByVal OriginalWIm As String, ByVal NewWIM As String, ByVal sIndex As Integer, ByVal Temp As String)
        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

但是WIMApplyImage 就不成功

Private Declare Function WIMApplyImage Lib "WIMGAPI.DLL" (ByVal hImage As IntPtr, ByVal lpszPath As String, ByVal dwApplyFlags As Integer) As Boolean
    Public Sub CWIM_WIMApplyImage(ByVal WimImg As String, ByVal Folder As String, ByVal sIndex As Integer)
        Dim s As IntPtr = WIMCreateFile(WimImg, WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, WIM_COMPRESS_NONE, WIM_OPENED_EXISTING)
        WIMSetTemporaryPath(s, "C:\Windows\Temp")
        Dim si As IntPtr = WIMLoadImage(s, sIndex)
        WIMApplyImage(si, Folder, sIndex)
        WIMCloseHandle(si)
    End Sub

不知道是哪里有错误?本人初学VB.NET,麻烦大神们帮忙看看!谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐