[togo] don't apply the 'set internal disks offline' policy

* This creates issue due to dism incompatibilities between Windows versions
  and some users are puzzled why they don't see their internal disks.
* Also make the bcdboot call more robust by using the system one if the USB one fails
* Also fix small issues in RunCommand() and MountVolume()
This commit is contained in:
Pete Batard 2015-06-24 20:00:20 +01:00
parent a9ee79bdad
commit cc6234296d
4 changed files with 45 additions and 19 deletions

View file

@ -842,6 +842,9 @@ BOOL MountVolume(char* drive_name, char *drive_guid)
char mounted_letter[16] = {0}; char mounted_letter[16] = {0};
DWORD size; DWORD size;
if (drive_name[0] == '?')
return FALSE;
// For fixed disks, Windows may already have remounted the volume, but with a different letter // For fixed disks, Windows may already have remounted the volume, but with a different letter
// than the one we want. If that's the case, we need to unmount first. // than the one we want. If that's the case, we need to unmount first.
if ( (GetVolumePathNamesForVolumeNameA(drive_guid, mounted_letter, sizeof(mounted_letter), &size)) if ( (GetVolumePathNamesForVolumeNameA(drive_guid, mounted_letter, sizeof(mounted_letter), &size))

View file

@ -1264,12 +1264,22 @@ out:
} }
// http://technet.microsoft.com/en-ie/library/jj721578.aspx // http://technet.microsoft.com/en-ie/library/jj721578.aspx
// As opposed to the technet guide above, we no longer set internal drives offline,
// due to people wondering why they can't see them by default, and also due to dism
// incompatibilities from one version of Windows to the next.
// Maybe when we use wimlib we'll review this, but for now just turn it off.
//#define SET_INTERNAL_DRIVES_OFFLINE
BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi) BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi)
{ {
char san_policy_path[] = "?:\\san_policy.xml", unattend_path[] = "?:\\Windows\\System32\\sysprep\\unattend.xml"; #ifdef SET_INTERNAL_DRIVES_OFFLINE
char *mounted_iso, *ms_efi = NULL, image[128], cmd[128]; static char san_policy_path[] = "?:\\san_policy.xml";
wchar_t wVolumeName[] = L"?:"; #endif
static char unattend_path[] = "?:\\Windows\\System32\\sysprep\\unattend.xml";
char *mounted_iso, *ms_efi = NULL, image[128], cmd[MAX_PATH], system_root[128];
unsigned char *buffer; unsigned char *buffer;
int i;
wchar_t wVolumeName[] = L"?:";
DWORD bufsize; DWORD bufsize;
ULONG cluster_size; ULONG cluster_size;
FILE* fd; FILE* fd;
@ -1340,17 +1350,27 @@ BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi)
} }
} }
static_sprintf(cmd, "%s\\Windows\\System32\\bcdboot.exe %s\\Windows /f ALL /s %s", // Try the 'bcdboot' command, first using the one from the target drive and, if that doesn't work, the system's
drive_name, drive_name, (use_ms_efi)?ms_efi:drive_name); uprintf("Enabling boot...");
uprintf("Enabling boot: '%s'", cmd); for (i = 0; i < 2; i++) {
if (RunCommand(cmd, NULL, TRUE) != 0) { if (i == 0)
static_sprintf(system_root, "%s\\Windows\\System32", drive_name);
else
GetSystemDirectoryA(system_root, sizeof(system_root));
static_sprintf(cmd, "%s\\bcdboot.exe %s\\Windows /f ALL /s %s",
system_root, drive_name, (use_ms_efi)?ms_efi:drive_name);
if (RunCommand(cmd, NULL, TRUE) == 0)
break;
}
if (i >= 2) {
// Fatal, as the UFD is unlikely to boot then // Fatal, as the UFD is unlikely to boot then
uprintf("Command '%s' failed to run", cmd); uprintf("Failed to enable boot - aborting", cmd);
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_ISO_EXTRACT); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_ISO_EXTRACT);
if (use_ms_efi) if (use_ms_efi)
AltUnmountVolume(ms_efi); AltUnmountVolume(ms_efi);
return FALSE; return FALSE;
} }
uprintf("Boot was successfully enabled using command '%s'", cmd);
if (use_ms_efi) { if (use_ms_efi) {
Sleep(200); Sleep(200);
@ -1360,10 +1380,12 @@ BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi)
UpdateProgress(OP_DOS, 99.9f); UpdateProgress(OP_DOS, 99.9f);
// The following are non fatal if they fail // The following are non fatal if they fail
#ifdef SET_INTERNAL_DRIVES_OFFLINE
uprintf("Applying 'san_policy.xml', to set the target's internal drives offline...");
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_TOGO_SAN_POLICY_XML), buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_TOGO_SAN_POLICY_XML),
_RT_RCDATA, "san_policy.xml", &bufsize, FALSE); _RT_RCDATA, "san_policy.xml", &bufsize, FALSE);
san_policy_path[0] = drive_name[0]; san_policy_path[0] = drive_name[0];
uprintf("Applying san_policy.xml...");
fd = fopenU(san_policy_path, "wb"); fd = fopenU(san_policy_path, "wb");
if ((fd == NULL) || (fwrite(buffer, 1, bufsize, fd) != bufsize)) { if ((fd == NULL) || (fwrite(buffer, 1, bufsize, fd) != bufsize)) {
uprintf("Could not write '%s'\n", san_policy_path); uprintf("Could not write '%s'\n", san_policy_path);
@ -1379,8 +1401,9 @@ BOOL SetupWinToGo(const char* drive_name, BOOL use_ms_efi)
if (RunCommand(cmd, NULL, TRUE) != 0) if (RunCommand(cmd, NULL, TRUE) != 0)
uprintf("Command '%s' failed to run", cmd); uprintf("Command '%s' failed to run", cmd);
} }
#endif
uprintf("Copying 'unattend.xml'"); uprintf("Copying 'unattend.xml', to disable the use of the Windows Recovery Environment...");
buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_TOGO_UNATTEND_XML), buffer = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_TOGO_UNATTEND_XML),
_RT_RCDATA, "unattend.xml", &bufsize, FALSE); _RT_RCDATA, "unattend.xml", &bufsize, FALSE);
unattend_path[0] = drive_name[0]; unattend_path[0] = drive_name[0];

View file

@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 242, 376 IDD_DIALOG DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 2.3.678" CAPTION "Rufus 2.3.679"
FONT 8, "Segoe UI", 400, 0, 0x1 FONT 8, "Segoe UI", 400, 0, 0x1
BEGIN BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -157,7 +157,7 @@ END
IDD_DIALOG_XP DIALOGEX 12, 12, 242, 376 IDD_DIALOG_XP DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 2.3.678" CAPTION "Rufus 2.3.679"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -283,7 +283,7 @@ END
IDD_DIALOG_RTL DIALOGEX 12, 12, 242, 376 IDD_DIALOG_RTL DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 2.3.678" CAPTION "Rufus 2.3.679"
FONT 8, "Segoe UI", 400, 0, 0x1 FONT 8, "Segoe UI", 400, 0, 0x1
BEGIN BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -415,7 +415,7 @@ END
IDD_DIALOG_RTL_XP DIALOGEX 12, 12, 242, 376 IDD_DIALOG_RTL_XP DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 2.3.678" CAPTION "Rufus 2.3.679"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -671,8 +671,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,3,678,0 FILEVERSION 2,3,679,0
PRODUCTVERSION 2,3,678,0 PRODUCTVERSION 2,3,679,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -689,13 +689,13 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "2.3.678" VALUE "FileVersion", "2.3.679"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2015 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2015 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe" VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "2.3.678" VALUE "ProductVersion", "2.3.679"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -561,7 +561,7 @@ DWORD RunCommand(const char* cmd, const char* dir, BOOL log)
if (!CreateProcessU(NULL, cmd, NULL, NULL, TRUE, if (!CreateProcessU(NULL, cmd, NULL, NULL, TRUE,
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, dir, &si, &pi)) { NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, dir, &si, &pi)) {
ret = GetLastError(); ret = GetLastError();
uprintf("Unable to launch command '%s': %s", WindowsErrorString()); uprintf("Unable to launch command '%s': %s", cmd, WindowsErrorString());
goto out; goto out;
} }