分享

ImageX and using window imaging from C++

 迎风初开 2011-10-03

To restore an example image ImageX can do this in 3min 25sec.  However from my code I get a total restore time of 9min 50sec.

 

I have captured some time information from the WIM calls and the attached program spend 3min 18sec in the WIMCreateFile and 6 min 41 sec in WIMApplyImage.

 

Does anyone know how imageX does the restore to achieve the times it gets?

 

Thanks

 

D

 

#include <stdio.h>
#include <windows.h>
#include <wimgapi.h>
#define IN
#define INOUT
//
//Callback function:
//
DWORD WINAPI ApplyCallback(DWORD dwMessageId, WPARAM wParam, LPARAM lParam, PVOID pvUserData) {
switch ( dwMessageId ) {
case WIM_MSG_SETRANGE:	// http://msdn.microsoft.com/en-us/library/7535a5c5-f72f-4c1e-90e9-d07a8d4132cd
printf ("File count to be restored %d\n", (DWORD) lParam);
break;
case WIM_MSG_SETPOS:	// http://msdn.microsoft.com/en-us/library/dd834954%28v=MSDN.10%29.aspx
if ((DWORD) lParam == 0) {
printf ("Starting apply\n");
} else {
printf ("Finished apply\n");
}
break;
case WIM_MSG_PROGRESS:	// http://msdn.microsoft.com/en-us/library/f0c291f5-2a40-4805-8d00-82e8b852275c
printf ("\rPercentage %d", (UINT) wParam);
if ((UINT) wParam == 100) {
printf ("\n");
}
break;
}
return WIM_MSG_SUCCESS;
}
LPWSTR MultiCharToUniChar(char* multiByteString) {
size_t len = strlen(multiByteString) + 1;
wchar_t *wideCharString = new wchar_t[len];
mbstowcs(wideCharString, multiByteString, len); // Convert multibyte string to wide-character string
return (LPWSTR)wideCharString;
}
int main(DWORD argc, char *argv[])
{
HANDLE WIMHandle = NULL;
HANDLE ImageHandle = NULL;
char wimSourceFile[] = "KDClient.WIM";
char wimApplyDirectory[] = "C:\\";
bool success = false;
printf ("Restoring up %s to %s\n", wimSourceFile, wimApplyDirectory);
char tempDirectory [MAX_PATH] = {0};
GetTempPath(MAX_PATH, tempDirectory);
printf ("Temp path being used is %s\n", tempDirectory);
LPWSTR WIMTempDirectory = MultiCharToUniChar (tempDirectory);
LPWSTR WIMSourceFile = MultiCharToUniChar (wimSourceFile);
LPWSTR WIMApplyDirectory = MultiCharToUniChar (wimApplyDirectory);
if (WIMRegisterMessageCallback( NULL, (FARPROC) ApplyCallback, NULL ) != INVALID_CALLBACK_VALUE) {
DWORD created = 0;
WIMHandle = WIMCreateFile (WIMSourceFile, WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_VERIFY, 0, &created );
if (WIMHandle) {
if (WIMSetTemporaryPath(WIMHandle, WIMTempDirectory)) {
DWORD imgIndex = 1;
ImageHandle = WIMLoadImage (WIMHandle, imgIndex);
if (ImageHandle) {
if (WIMApplyImage (ImageHandle, WIMApplyDirectory, WIM_FLAG_VERIFY)) {
success = true;
} else {
printf ("Failed to apply image. Error code %d\n", GetLastError());
}
if (!WIMCloseHandle(ImageHandle)) {
printf ("Failed to close image device correctly. Error code %d\n", GetLastError());
if (success) success = false;
}
} else {
printf ("Failed to load image. Error code %d\n", GetLastError());
}
} else {
printf ("Unable to set temp direcotry\n");
}
if (!WIMCloseHandle(WIMHandle)) {
printf ("Failed to WIM file correctly. Error code %d\n", GetLastError());
if (success) success = false;
}
} else {
printf ("Cannot open the WIM file. Error code %d\n", GetLastError());
}
} else {
printf ("Unable to register capture callback.\n");
}
return 0;
}


 

 

All Replies

Thursday, August 11, 2011 2:12 PM
 
Vote As Helpful

Have you tried to disable WIM_FLAG_VERIFY in both WIMCreateFile() and WIMApplyImage()?

I suppose that the verification may cost some CPU time in applying the image. In another way, you may use the imagex by enabling /VERIFY flag in the command line to have a compare.

What's the size of the volume are you applying?

 

Jimmy Zhu


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Report as abuse

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多