mirror of
https://github.com/Metabolix/HackBGRT.git
synced 2026-09-26 14:01:19 -07:00
Report if BCDEdit is not working
One possible cause for BCDEdit failure is Windows error 0x800703EE. "The volume for a file has been externally altered so that the opened file is no longer valid." Suggested solutions include disabling antivirus or backup software.
This commit is contained in:
+36
-6
@@ -144,10 +144,9 @@ public class Setup {
|
|||||||
*
|
*
|
||||||
* @param app Path to the application.
|
* @param app Path to the application.
|
||||||
* @param args The argument string.
|
* @param args The argument string.
|
||||||
* @param nullOnFail If set, return null if the program exits with a code other than 0, even if there was some output.
|
* @return The output and exit code.
|
||||||
* @return The output, or null if the execution failed.
|
|
||||||
*/
|
*/
|
||||||
public static string Execute(string app, string args, bool nullOnFail) {
|
public static (string Output, int ExitCode) Execute(string app, string args) {
|
||||||
Log($"Execute: {app} {args}");
|
Log($"Execute: {app} {args}");
|
||||||
try {
|
try {
|
||||||
var info = new ProcessStartInfo(app, args);
|
var info = new ProcessStartInfo(app, args);
|
||||||
@@ -157,13 +156,26 @@ public class Setup {
|
|||||||
string output = p.StandardOutput.ReadToEnd();
|
string output = p.StandardOutput.ReadToEnd();
|
||||||
p.WaitForExit();
|
p.WaitForExit();
|
||||||
Log($"Exit code: {p.ExitCode}, output:\n{output}\n\n");
|
Log($"Exit code: {p.ExitCode}, output:\n{output}\n\n");
|
||||||
return (nullOnFail && p.ExitCode != 0) ? null : output;
|
return (output, p.ExitCode);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log($"Execute failed: {e.ToString()}");
|
Log($"Execute failed: {e.ToString()}");
|
||||||
return null;
|
return (null, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute another process, return the output.
|
||||||
|
*
|
||||||
|
* @param app Path to the application.
|
||||||
|
* @param args The argument string.
|
||||||
|
* @param nullOnFail If set, return null if the program exits with a code other than 0, even if there was some output.
|
||||||
|
* @return The output, or null if the execution failed.
|
||||||
|
*/
|
||||||
|
public static string Execute(string app, string args, bool nullOnFail) {
|
||||||
|
var result = Execute(app, args);
|
||||||
|
return (nullOnFail && result.ExitCode != 0) ? null : result.Output;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for required privileges (access to ESP and EFI vars).
|
* Check for required privileges (access to ESP and EFI vars).
|
||||||
*
|
*
|
||||||
@@ -403,9 +415,27 @@ public class Setup {
|
|||||||
WriteLine("Dry run, skip enabling with BCDEdit.");
|
WriteLine("Dry run, skip enabling with BCDEdit.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var bcdeditEnum = Execute("bcdedit", "/enum firmware");
|
||||||
|
if (bcdeditEnum.ExitCode != 0) {
|
||||||
|
WriteLine("BCDEdit is not working. Fix it or try another method.");
|
||||||
|
if (bcdeditEnum.Output != null) {
|
||||||
|
var lastLine = bcdeditEnum.Output.Split("\n".ToCharArray()).Last();
|
||||||
|
WriteLine($"BCDEdit output: {lastLine}");
|
||||||
|
WriteLine("Disable antivirus, check your hard disk, or search 'how to fix 0x800703EE'.");
|
||||||
|
}
|
||||||
|
throw new SetupException("Failed to enable HackBGRT with BCDEdit!");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
var re = new Regex("[{][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}[}]");
|
var re = new Regex("[{][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}[}]");
|
||||||
var guid = re.Match(Execute("bcdedit", "/copy {bootmgr} /d HackBGRT", true)).Value;
|
var bcdCopy = Execute("bcdedit", "/copy {bootmgr} /d HackBGRT").Output;
|
||||||
|
if (bcdCopy == null) {
|
||||||
|
throw new SetupException("Failed to create a new BCDEdit entry for HackBGRT!");
|
||||||
|
}
|
||||||
|
var match = re.Match(bcdCopy);
|
||||||
|
if (!match.Success) {
|
||||||
|
throw new SetupException("Failed to get a GUID for the new BCDEdit entry for HackBGRT!");
|
||||||
|
}
|
||||||
|
var guid = match.Value;
|
||||||
Execute("bcdedit", $"/set {guid} device partition={Esp.Location}", true);
|
Execute("bcdedit", $"/set {guid} device partition={Esp.Location}", true);
|
||||||
Execute("bcdedit", $"/set {guid} path \\EFI\\HackBGRT\\loader.efi", true);
|
Execute("bcdedit", $"/set {guid} path \\EFI\\HackBGRT\\loader.efi", true);
|
||||||
foreach (var arg in new string[] { "locale", "inherit", "default", "resumeobject", "displayorder", "toolsdisplayorder", "timeout" }) {
|
foreach (var arg in new string[] { "locale", "inherit", "default", "resumeobject", "displayorder", "toolsdisplayorder", "timeout" }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user