diff --git a/src/format.c b/src/format.c index 4e1aee6b..5a0b25d8 100644 --- a/src/format.c +++ b/src/format.c @@ -1280,9 +1280,7 @@ BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi) #endif static char unattend_path[] = "?:\\Windows\\System32\\sysprep\\unattend.xml"; char *mounted_iso, *ms_efi = NULL, image[128], cmd[MAX_PATH]; - char usb_system_dir[] = "?:\\Windows\\System32"; unsigned char *buffer; - int i; wchar_t wVolumeName[] = L"?:"; DWORD bufsize; ULONG cluster_size; @@ -1291,7 +1289,6 @@ BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi) PF_INIT(FormatEx, Fmifs); uprintf("Windows To Go mode selected"); - usb_system_dir[0] = drive_name[0]; // Additional sanity checks if ( ((use_ms_efi) && (SelectedDrive.Geometry.MediaType != FixedMedia)) || ((nWindowsVersion < WINDOWS_8) || ((WimExtractCheck() & 4) == 0)) ) { @@ -1353,25 +1350,21 @@ BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi) AltUnmountVolume(ms_efi); return FALSE; } + Sleep(200); } - // Try the 'bcdboot' command, first using the one from the target drive and, if that doesn't work, the system's + // We invoke the 'bcdboot' command from the host, as the one from the drive produces problems (#558) + // Also, since Rufus should (usually) be running as a 32 bit app, on 64 bit systems, we need to use + // 'C:\Windows\Sysnative' and not 'C:\Windows\System32' to invoke bcdboot, as 'C:\Windows\System32' + // will get converted to 'C:\Windows\SysWOW64' behind the scenes, and ther is no bcdboot.exe there. uprintf("Enabling boot..."); - for (i = 0; i < 2; i++) { - static_sprintf(cmd, "%s\\bcdboot.exe %s\\Windows /f ALL /s %s", - (i==0)?usb_system_dir:system_dir, drive_name, (use_ms_efi)?ms_efi:drive_name); - if (RunCommand(cmd, NULL, TRUE) == 0) - break; + static_sprintf(cmd, "%s\\bcdboot.exe %s\\Windows /v /f ALL /s %s", sysnative_dir, + drive_name, (use_ms_efi)?ms_efi:drive_name); + if (RunCommand(cmd, sysnative_dir, TRUE) != 0) { + // Try to continue... but report a failure + uprintf("Failed to enable boot using command '%s'", cmd); + FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_ISO_EXTRACT); } - if (i >= 2) { - // Fatal, as the UFD is unlikely to boot then - uprintf("Failed to enable boot - aborting", cmd); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_ISO_EXTRACT); - if (use_ms_efi) - AltUnmountVolume(ms_efi); - return FALSE; - } - uprintf("Boot was successfully enabled using command '%s'", cmd); if (use_ms_efi) { Sleep(200); diff --git a/src/msapi_utf8.h b/src/msapi_utf8.h index 44a190bb..548878f7 100644 --- a/src/msapi_utf8.h +++ b/src/msapi_utf8.h @@ -433,6 +433,20 @@ static __inline UINT GetSystemDirectoryU(char* lpBuffer, UINT uSize) return ret; } +static __inline UINT GetSystemWindowsDirectoryU(char* lpBuffer, UINT uSize) +{ + UINT ret = 0, err = ERROR_INVALID_DATA; + walloc(lpBuffer, uSize); + ret = GetSystemWindowsDirectoryW(wlpBuffer, uSize); + err = GetLastError(); + if ((ret != 0) && ((ret = wchar_to_utf8_no_alloc(wlpBuffer, lpBuffer, uSize)) == 0)) { + err = GetLastError(); + } + wfree(lpBuffer); + SetLastError(err); + return ret; +} + static __inline DWORD GetTempPathU(DWORD nBufferLength, char* lpBuffer) { DWORD ret = 0, err = ERROR_INVALID_DATA; diff --git a/src/rufus.c b/src/rufus.c index f5669acd..b19b681c 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -129,7 +129,7 @@ char lost_translators[][6] = LOST_TRANSLATORS; OPENED_LIBRARIES_VARS; HINSTANCE hMainInstance; HWND hMainDialog, hLangToolbar = NULL, hUpdatesDlg = NULL; -char szFolderPath[MAX_PATH], app_dir[MAX_PATH], system_dir[MAX_PATH]; +char szFolderPath[MAX_PATH], app_dir[MAX_PATH], system_dir[MAX_PATH], sysnative_dir[MAX_PATH]; char* image_path = NULL; float fScale = 1.0f; int default_fs; @@ -2823,7 +2823,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine uprintf("Could not access UTF-16 args"); } - // Retrieve the current application directory as well as the system dir + // Retrieve the current application directory as well as the system & sysnative dirs if (GetCurrentDirectoryU(sizeof(app_dir), app_dir) == 0) { uprintf("Could not get current directory: %s", WindowsErrorString()); app_dir[0] = 0; @@ -2832,6 +2832,20 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine uprintf("Could not get system directory: %s", WindowsErrorString()); safe_strcpy(system_dir, sizeof(system_dir), "C:\\Windows\\System32"); } + // Construct Sysnative ourselves as there is no GetSysnativeDirectory() call + // By default (64bit app running on 64 bit OS or 32 bit app running on 32 bit OS) + // Sysnative and System32 are the same + safe_strcpy(sysnative_dir, sizeof(sysnative_dir), system_dir); + // But if the app is 32 bit and the OS is 64 bit, Sysnative must differ from System32 +#if (!defined(_WIN64) && !defined(BUILD64)) + if (is_x64()) { + if (GetSystemWindowsDirectoryU(sysnative_dir, sizeof(sysnative_dir)) == 0) { + uprintf("Could not get Windows directory: %s", WindowsErrorString()); + safe_strcpy(sysnative_dir, sizeof(sysnative_dir), "C:\\Windows"); + } + safe_strcat(sysnative_dir, sizeof(sysnative_dir), "\\Sysnative"); + } +#endif // Look for a .ini file in the current app directory static_sprintf(ini_path, "%s\\rufus.ini", app_dir); diff --git a/src/rufus.h b/src/rufus.h index 3c58d559..4b90a5ac 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -355,7 +355,7 @@ extern HWND hMainDialog, hLogDlg, hStatus, hDeviceList, hCapacity; extern HWND hPartitionScheme, hFileSystem, hClusterSize, hLabel, hBootType, hNBPasses, hLog; extern HWND hInfo, hProgress, hDiskID, hStatusToolbar; extern float fScale; -extern char szFolderPath[MAX_PATH], app_dir[MAX_PATH], system_dir[MAX_PATH]; +extern char szFolderPath[MAX_PATH], app_dir[MAX_PATH], system_dir[MAX_PATH], sysnative_dir[MAX_PATH]; extern char* image_path; extern DWORD FormatStatus, DownloadStatus; extern BOOL PromptOnError; diff --git a/src/rufus.rc b/src/rufus.rc index 356c9ccd..a7feb658 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 242, 376 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Rufus 2.3.702" +CAPTION "Rufus 2.3.703" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -317,8 +317,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,3,702,0 - PRODUCTVERSION 2,3,702,0 + FILEVERSION 2,3,703,0 + PRODUCTVERSION 2,3,703,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -335,13 +335,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.3.702" + VALUE "FileVersion", "2.3.703" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2015 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.3.702" + VALUE "ProductVersion", "2.3.703" END END BLOCK "VarFileInfo" diff --git a/src/stdfn.c b/src/stdfn.c index 6ffc2129..af86c6b2 100644 --- a/src/stdfn.c +++ b/src/stdfn.c @@ -544,7 +544,7 @@ DWORD RunCommand(const char* cmd, const char* dir, BOOL log) si.cb = sizeof(si); if (log) { - // NB: The size of a pipe is a suggestion, NOT an absolute gaurantee + // NB: The size of a pipe is a suggestion, NOT an absolute guarantee // This means that you may get a pipe of 4K even if you requested 1K if (!CreatePipe(&hOutputRead, &hOutputWrite, NULL, dwPipeSize)) { ret = GetLastError();