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.
Ihave captured some time information from the WIM calls and the attachedprogram spend 3min 18sec in the WIMCreateFile and 6 min 41 sec inWIMApplyImage.
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-d07a8d4132cdprintf ("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.aspxif ((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-82e8b852275cprintf ("\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 stringreturn (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;}
Have you tried to disable WIM_FLAG_VERIFY in both WIMCreateFile() and WIMApplyImage()?
I suppose that the verification may cost some CPU time in applyingthe image. In another way, you may use the imagex by enabling /VERIFYflag in the command line to have a compare.
What's the size of the volume are you applying?
Jimmy Zhu

聯(lián)系客服