From 34bdb423e96178dab288a9076798638d0307c407 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felipe=20Gonz=C3=A1lez=20Mart=C3=ADn?=
<158048821+felgmar@users.noreply.github.com>
Date: Sat, 17 Jan 2026 17:54:28 +0000
Subject: [PATCH 1/4] ConsoleApp: Improve error and parameter handling
Replaces 'AdditionalDriversDrive' with 'AdditionalDrive' in ArgumentParser for consistency. Updates Program.cs to log exception messages instead of rethrowing, providing clearer error output during execution.
---
ConsoleApp/src/ArgumentParser.cs | 4 ++--
ConsoleApp/src/Program.cs | 25 +++++++++++++++++--------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/ConsoleApp/src/ArgumentParser.cs b/ConsoleApp/src/ArgumentParser.cs
index 7deb9bb..4ca2def 100644
--- a/ConsoleApp/src/ArgumentParser.cs
+++ b/ConsoleApp/src/ArgumentParser.cs
@@ -59,7 +59,7 @@ internal static void ParseArgs(ref Parameters parameters, string[] args)
parameters.ImageFilePath = args[Array.IndexOf(args, arg) + 1].ToLowerInvariant();
continue;
case "/additionaldriversdrive":
- parameters.AdditionalDriversDrive = args[Array.IndexOf(args, arg) + 1].ToLowerInvariant();
+ parameters.AdditionalDrive = args[Array.IndexOf(args, arg) + 1].ToLowerInvariant();
continue;
case "/firmwaretype":
parameters.FirmwareType = args[Array.IndexOf(args, arg) + 1].ToUpperInvariant();
@@ -80,7 +80,7 @@ internal static void ParseArgs(ref Parameters parameters, string[] args)
Console.WriteLine($" Source Drive: {parameters.SourceDrive}");
Console.WriteLine($" Image Index: {parameters.ImageIndex}");
Console.WriteLine($" Image File Path: {parameters.ImageFilePath}");
- Console.WriteLine($" Additional Drivers Drive: {parameters.AdditionalDriversDrive}");
+ Console.WriteLine($" Additional Drivers Drive: {parameters.AdditionalDrive}");
Console.WriteLine($" Firmware Type: {parameters.FirmwareType}");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
diff --git a/ConsoleApp/src/Program.cs b/ConsoleApp/src/Program.cs
index 30d1231..aba4735 100644
--- a/ConsoleApp/src/Program.cs
+++ b/ConsoleApp/src/Program.cs
@@ -30,36 +30,45 @@ internal static int Main(string[] args)
Console.WriteLine($"Created by {ProgramInfo.GetAuthor()}");
#endif
}
- catch (Exception)
+ catch (Exception ex)
{
- throw;
+ Console.WriteLine($"An error has occurred: {ex.Message}");
}
try
{
ArgumentParser.ParseArgs(ref parameters, args);
}
- catch (Exception)
+ catch (Exception ex)
{
- throw;
+ Console.WriteLine($"An error has occurred: {ex.Message}");
}
try
{
InstallerManager.Configure(ref parameters);
}
- catch (Exception)
+ catch (Exception ex)
{
- throw;
+ Console.WriteLine($"An error has occurred: {ex.Message}");
+ }
+
+ try
+ {
+ InstallerManager.Prepare(ref parameters);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"An error has occurred: {ex.Message}");
}
try
{
InstallerManager.InstallWindows(ref parameters);
}
- catch (Exception)
+ catch (Exception ex)
{
- throw;
+ Console.WriteLine($"An error has occurred: {ex.Message}");
}
return 0;
From 91ed137c2b4f29e7c13ebd3f9d7a4aefed52170a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felipe=20Gonz=C3=A1lez=20Mart=C3=ADn?=
<158048821+felgmar@users.noreply.github.com>
Date: Sat, 17 Jan 2026 17:55:23 +0000
Subject: [PATCH 2/4] WindowsInstallerLib: Rewrite logic and improve parameter
handling
Refactored disk and driver parameter names for clarity, improved privilege checks, and streamlined user input validation in InstallerManager. Replaced DiskManager.ListAll with GetDisks to return disk info programmatically. Enhanced ProcessManager with more detailed console output during disk formatting. Separated preparation and installation logic in InstallerManager for better structure and error handling.
---
WindowsInstallerLib/src/DeployManager.cs | 72 ++++-----
WindowsInstallerLib/src/DiskManager.cs | 50 ++----
WindowsInstallerLib/src/InstallerManager.cs | 162 ++++++++------------
WindowsInstallerLib/src/ProcessManager.cs | 13 +-
4 files changed, 123 insertions(+), 174 deletions(-)
diff --git a/WindowsInstallerLib/src/DeployManager.cs b/WindowsInstallerLib/src/DeployManager.cs
index 1b9e272..6181ff3 100644
--- a/WindowsInstallerLib/src/DeployManager.cs
+++ b/WindowsInstallerLib/src/DeployManager.cs
@@ -337,49 +337,35 @@ internal static DismImageInfoCollection GetImageInfoT(ref Parameters parameters)
///
internal static void InstallAdditionalDrivers(ref Parameters parameters)
{
+ bool IS_ADMIN = PrivilegesManager.IsAdmin();
+
DismSession? session = null;
- ArgumentException.ThrowIfNullOrWhiteSpace(parameters.AdditionalDriversDrive, nameof(parameters));
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.AdditionalDrive, nameof(parameters));
- if (!PrivilegesManager.IsAdmin())
+ switch (IS_ADMIN)
{
- throw new UnauthorizedAccessException("You do not have enough privileges to install additional drivers.");
+ case true:
+ try
+ {
+ DismApi.Initialize(DismLogLevel.LogErrorsWarnings);
+ }
+ catch (DismException)
+ {
+ throw;
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ break;
+ case false:
+ throw new UnauthorizedAccessException("You do not have enough privileges to initialize the DISM API.");
}
try
{
- switch (PrivilegesManager.IsAdmin())
- {
- case true:
- try
- {
- DismApi.Initialize(DismLogLevel.LogErrorsWarnings);
- }
- catch (DismException)
- {
- throw;
- }
- catch (Exception)
- {
- throw;
- }
- break;
- case false:
- throw new UnauthorizedAccessException("You do not have enough privileges to initialize the DISM API.");
- }
-
- try
- {
- session ??= DismApi.OpenOfflineSession(parameters.DestinationDrive);
- }
- catch (DismException)
- {
- throw;
- }
- catch (Exception)
- {
- throw;
- }
+ session ??= DismApi.OpenOfflineSession(parameters.DestinationDrive);
}
catch (DismException)
{
@@ -392,7 +378,7 @@ internal static void InstallAdditionalDrivers(ref Parameters parameters)
try
{
- DismApi.AddDriversEx(session, parameters.AdditionalDriversDrive, false, true);
+ DismApi.AddDriversEx(session, parameters.AdditionalDrive, false, true);
}
finally
{
@@ -416,9 +402,11 @@ internal static void InstallAdditionalDrivers(ref Parameters parameters)
/// Thrown if the current process does not have administrative privileges required to perform the installation.
internal static int InstallBootloader(ref Parameters parameters)
{
- ArgumentException.ThrowIfNullOrWhiteSpace(parameters.DestinationDrive, nameof(parameters.DestinationDrive));
- ArgumentException.ThrowIfNullOrWhiteSpace(parameters.EfiDrive, nameof(parameters.EfiDrive));
- ArgumentException.ThrowIfNullOrWhiteSpace(parameters.FirmwareType, nameof(parameters.FirmwareType));
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.DestinationDrive, nameof(parameters));
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.EfiDrive, nameof(parameters));
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.FirmwareType, nameof(parameters));
+
+ bool IS_ADMIN = PrivilegesManager.IsAdmin();
string EFI_BOOT_PATH = Path.Join(parameters.EfiDrive, @"\EFI\Boot");
string EFI_MICROSOFT_PATH = Path.Join(parameters.EfiDrive, @"\EFI\Microsoft");
@@ -428,7 +416,7 @@ internal static int InstallBootloader(ref Parameters parameters)
bool EFI_MICROSOFT_EXISTS = Directory.Exists(EFI_MICROSOFT_PATH);
bool WINDIR_EXISTS = Directory.Exists(WINDIR_PATH);
- if (!PrivilegesManager.IsAdmin())
+ if (IS_ADMIN)
{
throw new UnauthorizedAccessException($"You do not have enough privileges to install the bootloader to {parameters.EfiDrive}");
}
@@ -445,9 +433,8 @@ internal static int InstallBootloader(ref Parameters parameters)
throw new DirectoryNotFoundException(@$"The directory {WINDIR_PATH} does not exist!");
}
- Console.WriteLine($"Firmware type is set to: {parameters.FirmwareType}");
Console.WriteLine($"\n==> Installing bootloader to drive {parameters.EfiDrive} in disk {parameters.DiskNumber}");
- ProcessManager.StartCmdProcess("bcdboot", @$"{WINDIR_PATH} /s {parameters.EfiDrive} /f {parameters.FirmwareType}");
+ ProcessManager.StartCmdProcess("bcdboot.exe", @$"{WINDIR_PATH} /s {parameters.EfiDrive} /f {parameters.FirmwareType}");
}
catch (IOException)
{
@@ -457,7 +444,6 @@ internal static int InstallBootloader(ref Parameters parameters)
{
throw;
}
-
return ProcessManager.ExitCode;
}
}
diff --git a/WindowsInstallerLib/src/DiskManager.cs b/WindowsInstallerLib/src/DiskManager.cs
index 7f4780f..9189b67 100644
--- a/WindowsInstallerLib/src/DiskManager.cs
+++ b/WindowsInstallerLib/src/DiskManager.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Management;
@@ -51,50 +53,32 @@ internal static int FormatDisk(ref Parameters parameters)
/// model, and device ID for each disk drive found. Note that this method is intended for internal use
/// and writes directly to the console. It does not return the retrieved data or provide a way to
/// programmatically access it.
- internal static void ListAll()
+ internal static SortedDictionary GetDisks()
{
+ SortedDictionary SystemDisks = [];
+
try
{
- WqlObjectQuery DeviceTable = new("SELECT * FROM Win32_DiskDrive");
- ManagementObjectSearcher DeviceInfo = new(DeviceTable);
- foreach (ManagementObject o in DeviceInfo.Get().Cast())
+ WqlObjectQuery Query = new("SELECT * FROM Win32_DiskDrive");
+ ManagementObjectSearcher ObjectSearcher = new(Query);
+ foreach (ManagementObject obj in ObjectSearcher.Get().Cast())
{
- Console.WriteLine("Disk number = " + o["Index"]);
- Console.WriteLine("Model = " + o["Model"]);
- Console.WriteLine("DeviceID = " + o["DeviceID"]);
- Console.WriteLine("");
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
+ int Index = Convert.ToInt32(obj["Index"], CultureInfo.CurrentCulture);
+ string? Model = obj["Model"].ToString();
- ///
- /// Retrieves an array of all available drive information on the system.
- ///
- /// An array of objects representing the drives available on the system.
- internal static DriveInfo[] GetDisksT()
- {
- try
- {
- DriveInfo[] drives = DriveInfo.GetDrives();
+ if (Model != null)
+ {
+ SystemDisks.Add(Index, Model);
+ }
+ }
- return drives;
- }
- catch (IOException)
- {
- throw;
- }
- catch (UnauthorizedAccessException)
- {
- throw;
}
catch (Exception)
{
throw;
}
+
+ return SystemDisks;
}
}
}
diff --git a/WindowsInstallerLib/src/InstallerManager.cs b/WindowsInstallerLib/src/InstallerManager.cs
index 5107214..228f0dc 100644
--- a/WindowsInstallerLib/src/InstallerManager.cs
+++ b/WindowsInstallerLib/src/InstallerManager.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Runtime.Versioning;
@@ -17,7 +18,7 @@ namespace WindowsInstallerLib
/// Gets or sets the source drive containing the data to be imaged.
/// Gets or sets the index of the image within the image file to be applied.
/// Gets or sets the file path of the image file to be used in the operation.
- /// Gets or sets a value indicating whether additional drivers should be installed during the imaging process.
+ /// Gets or sets a value indicating whether additional drivers should be installed during the imaging process.
/// Gets or sets the firmware type of the system being imaged.
[SupportedOSPlatform("windows")]
public struct Parameters(string DestinationDrive,
@@ -26,7 +27,7 @@ public struct Parameters(string DestinationDrive,
string SourceDrive,
int ImageIndex,
string ImageFilePath,
- string AdditionalDriversDrive,
+ string AdditionalDrive,
string FirmwareType)
{
public string DestinationDrive { get; set; } = DestinationDrive;
@@ -35,7 +36,7 @@ public struct Parameters(string DestinationDrive,
public string SourceDrive { get; set; } = SourceDrive;
public int ImageIndex { get; set; } = ImageIndex;
public string ImageFilePath { get; set; } = ImageFilePath;
- public string AdditionalDriversDrive { get; set; } = AdditionalDriversDrive;
+ public string AdditionalDrive { get; set; } = AdditionalDrive;
public string FirmwareType { get; set; } = FirmwareType;
}
@@ -62,15 +63,14 @@ public sealed class InstallerManager
public static void Configure(ref Parameters parameters)
{
#region DestinationDrive
- if (string.IsNullOrEmpty(parameters.DestinationDrive) ||
- string.IsNullOrWhiteSpace(parameters.DestinationDrive))
+ if (string.IsNullOrWhiteSpace(parameters.DestinationDrive))
{
- string p_DestinationDrive;
-
Console.Write("\n==> Type the mountpoint to use for deploying Windows (e.g. Z:): ");
+
try
{
- p_DestinationDrive = Console.ReadLine() ?? throw new ArgumentNullException(nameof(parameters), "DestinationDrive is null!");
+ parameters.DestinationDrive = Console.ReadLine() ??
+ throw new ArgumentException("A valid destination drive is required.", nameof(parameters));
}
catch (IOException)
{
@@ -89,35 +89,28 @@ public static void Configure(ref Parameters parameters)
throw;
}
- ArgumentException.ThrowIfNullOrWhiteSpace(p_DestinationDrive);
-
- if (p_DestinationDrive.Length != 2 ||
- p_DestinationDrive.Length > 2)
+ if (parameters.DestinationDrive.Length > 2 ||
+ parameters.DestinationDrive.Length < 2)
{
- throw new ArgumentException(@$"Invalid source drive {p_DestinationDrive}. Too many characters.");
+ throw new ArgumentException($"Invalid destination drive {parameters.DestinationDrive}.");
}
- if (p_DestinationDrive.StartsWith(':') ||
- !p_DestinationDrive.EndsWith(':'))
+ if (parameters.DestinationDrive.StartsWith(':') || !parameters.DestinationDrive.EndsWith(':'))
{
- throw new InvalidDataException(@$"Invalid source drive {p_DestinationDrive}. A valid drive is for example: 'Z:'.");
+ throw new InvalidDataException($"Invalid source drive {parameters.DestinationDrive}.");
}
-
- parameters.DestinationDrive = p_DestinationDrive;
}
#endregion
#region EfiDrive
- if (string.IsNullOrEmpty(parameters.EfiDrive) ||
- string.IsNullOrWhiteSpace(parameters.EfiDrive))
+ if (string.IsNullOrWhiteSpace(parameters.EfiDrive))
{
- string p_EfiDrive;
-
Console.Write("\n==> Type the mountpoint to use for the bootloader (e.g. Y:): ");
try
{
- p_EfiDrive = Console.ReadLine() ?? throw new ArgumentNullException(nameof(parameters), "EfiDrive is null!"); ;
+ parameters.EfiDrive = Console.ReadLine() ??
+ throw new ArgumentException("A valid EFI drive is required.", nameof(parameters));
}
catch (IOException)
{
@@ -136,32 +129,31 @@ public static void Configure(ref Parameters parameters)
throw;
}
- ArgumentException.ThrowIfNullOrWhiteSpace(p_EfiDrive);
-
- if (p_EfiDrive.StartsWith(':'))
+ if (parameters.EfiDrive.StartsWith(':'))
{
- throw new ArgumentException(@$"Invalid EFI drive {p_EfiDrive}, it must have a colon at the end not at the beginning. For example: 'Y:'.");
+ throw new ArgumentException(@$"Invalid EFI drive {parameters.EfiDrive}, it must have a colon at the end not at the beginning. For example: 'Y:'.");
}
- else if (!p_EfiDrive.EndsWith(':'))
+
+ if (!parameters.EfiDrive.EndsWith(':'))
{
- throw new ArgumentException($"Invalid EFI drive {p_EfiDrive}, it must have a colon. For example: 'Y:'.");
+ throw new ArgumentException($"Invalid EFI drive {parameters.EfiDrive}, it must have a colon. For example: 'Y:'.");
}
-
- parameters.EfiDrive = p_EfiDrive;
}
#endregion
#region DiskNumber
- if (string.IsNullOrEmpty(parameters.DiskNumber.ToString()) ||
- string.IsNullOrWhiteSpace(parameters.DiskNumber.ToString()) ||
- parameters.DiskNumber == -1)
+ if (string.IsNullOrWhiteSpace(parameters.DiskNumber.ToString()) || parameters.DiskNumber == -1)
{
- int p_DiskNumber;
+ Console.WriteLine("\n==> These are the disks available on your system:");
try
{
- Console.WriteLine("\n==> These are the disks available on your system:");
- DiskManager.ListAll();
+ SortedDictionary Disks = DiskManager.GetDisks();
+
+ foreach (KeyValuePair Disk in Disks)
+ {
+ Console.WriteLine("Disk number: {0}\nDisk model: {1}\n", Disk.Key, Disk.Value);
+ }
}
catch (Exception)
{
@@ -171,7 +163,7 @@ public static void Configure(ref Parameters parameters)
Console.Write("\n==> Please type the disk number to format (e.g. 0): ");
try
{
- p_DiskNumber = Convert.ToInt32(Console.ReadLine(), CultureInfo.CurrentCulture);
+ parameters.DiskNumber = Convert.ToInt32(Console.ReadLine(), CultureInfo.CurrentCulture);
}
catch (FormatException)
{
@@ -189,21 +181,18 @@ public static void Configure(ref Parameters parameters)
{
throw;
}
-
- parameters.DiskNumber = p_DiskNumber;
}
#endregion
#region SourceDrive
- if (string.IsNullOrEmpty(parameters.SourceDrive) ||
- string.IsNullOrWhiteSpace(parameters.SourceDrive))
+ if (string.IsNullOrWhiteSpace(parameters.SourceDrive))
{
- string? p_SourceDrive;
+ Console.Write("\n==> Specify the mount point where the source are mounted at (e.g. X:): ");
- Console.Write("\n==> Specify the mountpount where the source are mounted at (e.g. X:): ");
try
{
- p_SourceDrive = Console.ReadLine();
+ parameters.SourceDrive = Console.ReadLine() ??
+ throw new ArgumentException("A sourced drive is required.", nameof(parameters));
}
catch (IOException)
{
@@ -222,74 +211,49 @@ public static void Configure(ref Parameters parameters)
throw;
}
- ArgumentException.ThrowIfNullOrWhiteSpace(p_SourceDrive);
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.SourceDrive);
- if (p_SourceDrive.StartsWith(':'))
+ if (parameters.SourceDrive.StartsWith(':'))
{
- throw new ArgumentException(@$"Invalid source drive {p_SourceDrive}, it must have a colon at the end not at the beginning. For example: 'H:'.");
+ throw new ArgumentException(@$"Invalid source drive {parameters.SourceDrive}, it must have a colon at the end not at the beginning. For example: 'H:'.");
}
- else if (!p_SourceDrive.EndsWith(':'))
+ else if (!parameters.SourceDrive.EndsWith(':'))
{
- throw new ArgumentException($"Invalid source drive {p_SourceDrive}, it must have a colon. For example: 'H:'.");
+ throw new ArgumentException($"Invalid source drive {parameters.SourceDrive}, it must have a colon. For example: 'H:'.");
}
-
- parameters.SourceDrive = p_SourceDrive;
}
#endregion
#region ImageFilePath
- if (string.IsNullOrEmpty(parameters.ImageFilePath) ||
- string.IsNullOrWhiteSpace(parameters.ImageFilePath))
+ if (string.IsNullOrWhiteSpace(parameters.ImageFilePath))
{
- string p_ImageFilePath = DeployManager.GetImageFile(ref parameters);
+ parameters.ImageFilePath = DeployManager.GetImageFile(ref parameters);
- Console.WriteLine($"\nImage file path has been set to {p_ImageFilePath}.");
-
- parameters.ImageFilePath = p_ImageFilePath;
+ Console.WriteLine($"\nImage file path has been set to {parameters.ImageFilePath}.");
}
#endregion
#region ImageIndex
- if (string.IsNullOrEmpty(parameters.ImageIndex.ToString()) ||
- string.IsNullOrWhiteSpace(parameters.ImageIndex.ToString()) ||
- parameters.ImageIndex == -1)
+ if (parameters.ImageIndex == -1)
{
DeployManager.GetImageInfo(ref parameters);
Console.Write("\n==> Type the index number of the Windows edition you wish to install (e.g. 1): ");
- string? SelectedIndex = Console.ReadLine();
-
- if (string.IsNullOrEmpty(SelectedIndex) || string.IsNullOrWhiteSpace(SelectedIndex))
- {
- throw new ArgumentException("No Windows edition was specified.");
- }
-
- parameters.ImageIndex = Convert.ToInt32(SelectedIndex, CultureInfo.CurrentCulture);
+ parameters.ImageIndex = Convert.ToInt32(Console.ReadLine() ??
+ throw new ArgumentException("No Windows edition was specified."), CultureInfo.CurrentCulture);
}
#endregion
#region FirmwareType
- if (string.IsNullOrEmpty(parameters.FirmwareType) ||
- string.IsNullOrWhiteSpace(parameters.FirmwareType))
+ if (string.IsNullOrWhiteSpace(parameters.FirmwareType))
{
- switch (SystemInfoManager.IsEFI())
- {
- case true:
- parameters.FirmwareType = "UEFI";
- Console.WriteLine($"\nThe installer has set the firmware type to {parameters.FirmwareType}.", ConsoleColor.Yellow);
- break;
- case false:
- parameters.FirmwareType = "BIOS";
- Console.WriteLine($"\nThe installer has set the firmware type to {parameters.FirmwareType}.", ConsoleColor.Yellow);
- break;
- default:
- throw new InvalidDataException($"Invalid firmware type: {parameters.FirmwareType}");
- }
+ parameters.FirmwareType = SystemInfoManager.IsEFI() ? "UEFI" : "BIOS";
+ Console.WriteLine($"\nThe installer has set the firmware type to {parameters.FirmwareType}.", ConsoleColor.Yellow);
}
#endregion
- #region AdditionalDriversList
- if (string.IsNullOrWhiteSpace(parameters.AdditionalDriversDrive))
+ #region AdditionalDrive
+ if (string.IsNullOrWhiteSpace(parameters.AdditionalDrive))
{
Console.Write("\n=> Do you want to add additional drivers to your installation?: [Y/N]: ");
string? UserWantsExtraDrivers = Console.ReadLine()?.ToLower(CultureInfo.CurrentCulture);
@@ -317,7 +281,7 @@ public static void Configure(ref Parameters parameters)
throw new FileNotFoundException($"The directory {driversPath} does not exist");
}
- parameters.AdditionalDriversDrive = driversPath;
+ parameters.AdditionalDrive = driversPath;
break;
default:
return;
@@ -340,7 +304,7 @@ public static void Configure(ref Parameters parameters)
/// Thrown if the object contains invalid or missing values, such as: - Disk
/// number is -1. - EFI drive is null, empty, or whitespace.
[SupportedOSPlatform("windows")]
- public static void InstallWindows(ref Parameters parameters)
+ public static void Prepare(ref Parameters parameters)
{
if (parameters.DiskNumber.Equals(-1))
{
@@ -352,10 +316,11 @@ public static void InstallWindows(ref Parameters parameters)
throw new InvalidDataException("No EFI drive was specified, required for the bootloader installation.");
}
- ArgumentException.ThrowIfNullOrWhiteSpace(parameters.DestinationDrive);
- ArgumentException.ThrowIfNullOrWhiteSpace(parameters.ImageFilePath);
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.DestinationDrive, parameters.DestinationDrive);
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.EfiDrive, parameters.EfiDrive);
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.ImageFilePath, parameters.ImageFilePath);
ArgumentOutOfRangeException.ThrowIfEqual(parameters.ImageIndex, -1);
- ArgumentException.ThrowIfNullOrWhiteSpace(parameters.FirmwareType);
+ ArgumentException.ThrowIfNullOrWhiteSpace(parameters.FirmwareType, parameters.FirmwareType);
try
{
@@ -365,32 +330,35 @@ public static void InstallWindows(ref Parameters parameters)
{
Console.WriteLine($"An error occurred while formatting the disk: {ex}", ConsoleColor.Red);
}
+ }
+ public static void InstallWindows(ref Parameters parameters)
+ {
try
{
DeployManager.ApplyImage(ref parameters);
}
- catch (Exception ex)
+ catch
{
- Console.WriteLine($"An error occurred while applying the image: {ex}", ConsoleColor.Red);
+ throw;
}
try
{
DeployManager.InstallAdditionalDrivers(ref parameters);
}
- catch (Exception ex)
+ catch
{
- Console.WriteLine($"An error occurred when installing additional drivers: {ex}", ConsoleColor.Yellow);
+ throw;
}
try
{
DeployManager.InstallBootloader(ref parameters);
}
- catch (Exception ex)
+ catch
{
- Console.WriteLine($"An error occurred while installing the bootloader: {ex}", ConsoleColor.Red);
+ throw;
}
}
}
diff --git a/WindowsInstallerLib/src/ProcessManager.cs b/WindowsInstallerLib/src/ProcessManager.cs
index f4859ce..9b5264d 100644
--- a/WindowsInstallerLib/src/ProcessManager.cs
+++ b/WindowsInstallerLib/src/ProcessManager.cs
@@ -86,20 +86,31 @@ internal static int StartDiskPartProcess(int DiskNumber, string EfiDrive, string
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.CreateNoWindow = true;
+
process.Start();
Console.WriteLine($"Formatting disk {DiskNumber}, please wait...");
process.StandardInput.WriteLine($"select disk {DiskNumber}");
process.StandardInput.WriteLine("clean");
+ Console.WriteLine($"Cleaning disk {DiskNumber}...");
process.StandardInput.WriteLine("convert gpt");
+ Console.WriteLine($"Converting disk {DiskNumber} to GPT");
process.StandardInput.WriteLine("create partition efi size=100");
- process.StandardInput.WriteLine("create partition msr size=16");
+ Console.WriteLine("Creating a 100MB EFI partition...");
process.StandardInput.WriteLine("format fs=fat32 quick");
+ Console.WriteLine("Formatting EFI partition with FAT32...");
process.StandardInput.WriteLine($"assign letter {EfiDrive}");
+ Console.WriteLine($"Assigning letter {EfiDrive} to EFI partition...");
+ process.StandardInput.WriteLine("create partition msr size=16");
+ Console.WriteLine("Creating MSR partition...");
process.StandardInput.WriteLine("create partition primary");
+ Console.WriteLine($"Creating main partition...");
process.StandardInput.WriteLine("format fs=ntfs quick");
+ Console.WriteLine($"Formatting main partition with NTFS...");
process.StandardInput.WriteLine($"assign letter {DestinationDrive}");
+ Console.WriteLine($"Assigning letter {DestinationDrive} to main partition...");
process.StandardInput.WriteLine("exit");
process.WaitForExit();
From ed439e149b953b21b17ac34c00d0d410abce79a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felipe=20Gonz=C3=A1lez=20Mart=C3=ADn?=
<158048821+felgmar@users.noreply.github.com>
Date: Sat, 17 Jan 2026 17:56:01 +0000
Subject: [PATCH 3/4] WindowsInstallerLib: bump version to 1.1.5.0
---
WindowsInstallerLib/WindowsInstallerLib.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/WindowsInstallerLib/WindowsInstallerLib.csproj b/WindowsInstallerLib/WindowsInstallerLib.csproj
index 3969d30..4965f4d 100644
--- a/WindowsInstallerLib/WindowsInstallerLib.csproj
+++ b/WindowsInstallerLib/WindowsInstallerLib.csproj
@@ -8,7 +8,7 @@
none
$(AssemblyName)
latest
- 1.1.4.0
+ 1.1.5.0
x64
true
From 60405122624b78c0defcbfb2bbb0cd3741c36bb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felipe=20Gonz=C3=A1lez=20Mart=C3=ADn?=
<158048821+felgmar@users.noreply.github.com>
Date: Sat, 17 Jan 2026 17:56:33 +0000
Subject: [PATCH 4/4] ConsoleApp: bump version to 0.0.8.0
---
ConsoleApp/ConsoleApp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ConsoleApp/ConsoleApp.csproj b/ConsoleApp/ConsoleApp.csproj
index da2b86d..c8aea25 100644
--- a/ConsoleApp/ConsoleApp.csproj
+++ b/ConsoleApp/ConsoleApp.csproj
@@ -12,7 +12,7 @@
none
latest-recommended
ConsoleApp.Program
- 0.0.7.0
+ 0.0.8.0
true
app.manifest