diff --git a/src/c#/GeneralUpdate.Core/Driver/DisableUACCommand.cs b/src/c#/GeneralUpdate.Core/Driver/DisableUACCommand.cs
new file mode 100644
index 00000000..7eb324d7
--- /dev/null
+++ b/src/c#/GeneralUpdate.Core/Driver/DisableUACCommand.cs
@@ -0,0 +1,13 @@
+namespace GeneralUpdate.Core.Driver
+{
+ ///
+ /// Command to disable User Account Control (UAC) via script execution.
+ /// The script content is not managed by this class; only the script entry point is provided.
+ ///
+ public class DisableUACCommand : ScriptCommand
+ {
+ public DisableUACCommand(string scriptPath) : base(scriptPath)
+ {
+ }
+ }
+}
diff --git a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs
index e396e2a6..ea9424e8 100644
--- a/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs
+++ b/src/c#/GeneralUpdate.Core/Driver/DriverInformation.cs
@@ -18,6 +18,16 @@ public class DriverInformation
public string OutPutDirectory { get; private set; }
public string DriverDirectory { get; private set; }
+
+ ///
+ /// Path to the script that disables UAC.
+ ///
+ public string DisableUACScriptPath { get; private set; }
+
+ ///
+ /// Path to the script that restores UAC.
+ ///
+ public string RestoreUACScriptPath { get; private set; }
///
/// A collection of driver files to be backed up.
@@ -54,6 +64,18 @@ public Builder SetFieldMappings(Dictionary fieldMappings)
_information.FieldMappings = fieldMappings;
return this;
}
+
+ public Builder SetDisableUACScriptPath(string scriptPath)
+ {
+ _information.DisableUACScriptPath = scriptPath;
+ return this;
+ }
+
+ public Builder SetRestoreUACScriptPath(string scriptPath)
+ {
+ _information.RestoreUACScriptPath = scriptPath;
+ return this;
+ }
public DriverInformation Build()
{
diff --git a/src/c#/GeneralUpdate.Core/Driver/RestoreUACCommand.cs b/src/c#/GeneralUpdate.Core/Driver/RestoreUACCommand.cs
new file mode 100644
index 00000000..1b7e2a82
--- /dev/null
+++ b/src/c#/GeneralUpdate.Core/Driver/RestoreUACCommand.cs
@@ -0,0 +1,13 @@
+namespace GeneralUpdate.Core.Driver
+{
+ ///
+ /// Command to restore User Account Control (UAC) via script execution.
+ /// The script content is not managed by this class; only the script entry point is provided.
+ ///
+ public class RestoreUACCommand : ScriptCommand
+ {
+ public RestoreUACCommand(string scriptPath) : base(scriptPath)
+ {
+ }
+ }
+}
diff --git a/src/c#/GeneralUpdate.Core/Driver/ScriptCommand.cs b/src/c#/GeneralUpdate.Core/Driver/ScriptCommand.cs
new file mode 100644
index 00000000..7251ced7
--- /dev/null
+++ b/src/c#/GeneralUpdate.Core/Driver/ScriptCommand.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Diagnostics;
+using GeneralUpdate.Common.Shared;
+
+namespace GeneralUpdate.Core.Driver
+{
+ ///
+ /// Base class for executing script commands.
+ ///
+ public abstract class ScriptCommand : DriverCommand
+ {
+ protected string ScriptPath { get; }
+
+ protected ScriptCommand(string scriptPath)
+ {
+ if (string.IsNullOrWhiteSpace(scriptPath))
+ throw new ArgumentNullException(nameof(scriptPath), "Script path cannot be null or empty.");
+
+ ScriptPath = scriptPath;
+ }
+
+ public override void Execute()
+ {
+ ExecuteScript(ScriptPath);
+ }
+
+ ///
+ /// Execute a script file.
+ ///
+ /// Path to the script file to execute.
+ protected virtual void ExecuteScript(string scriptPath)
+ {
+ if (!System.IO.File.Exists(scriptPath))
+ throw new ApplicationException($"Script file not found: {scriptPath}");
+
+ var processStartInfo = new ProcessStartInfo
+ {
+ WindowStyle = ProcessWindowStyle.Hidden,
+ FileName = scriptPath,
+ UseShellExecute = true,
+ Verb = "runas"
+ };
+
+ var process = new Process();
+ try
+ {
+ process.StartInfo = processStartInfo;
+ process.Start();
+ process.WaitForExit();
+
+ if (process.ExitCode != 0)
+ throw new ApplicationException($"Script execution failed for '{scriptPath}' with exit code: {process.ExitCode}");
+
+ GeneralTracer.Info($"Script executed successfully: {scriptPath}");
+ }
+ finally
+ {
+ process.Dispose();
+ }
+ }
+ }
+}
diff --git a/src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs b/src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs
index c96ce6b0..5fb1d7b7 100644
--- a/src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs
+++ b/src/c#/GeneralUpdate.Core/Pipeline/DriverMiddleware.cs
@@ -29,17 +29,37 @@ public Task InvokeAsync(PipelineContext context)
if (fieldMappings == null || fieldMappings.Count == 0)
return;
- var information = new DriverInformation.Builder()
+ var disableUACScriptPath = context.Get("DisableUACScriptPath");
+ var restoreUACScriptPath = context.Get("RestoreUACScriptPath");
+
+ var builder = new DriverInformation.Builder()
.SetDriverFileExtension(FileExtension)
.SetOutPutDirectory(outPutPath)
.SetDriverDirectory(patchPath)
- .SetFieldMappings(fieldMappings)
- .Build();
+ .SetFieldMappings(fieldMappings);
+
+ if (!string.IsNullOrWhiteSpace(disableUACScriptPath))
+ builder.SetDisableUACScriptPath(disableUACScriptPath);
+
+ if (!string.IsNullOrWhiteSpace(restoreUACScriptPath))
+ builder.SetRestoreUACScriptPath(restoreUACScriptPath);
+
+ var information = builder.Build();
var processor = new DriverProcessor();
+
+ // Disable UAC before driver operations if script path is provided
+ if (!string.IsNullOrWhiteSpace(information.DisableUACScriptPath))
+ processor.AddCommand(new DisableUACCommand(information.DisableUACScriptPath));
+
processor.AddCommand(new BackupDriverCommand(information));
processor.AddCommand(new DeleteDriverCommand(information));
processor.AddCommand(new InstallDriverCommand(information));
+
+ // Restore UAC after driver operations if script path is provided
+ if (!string.IsNullOrWhiteSpace(information.RestoreUACScriptPath))
+ processor.AddCommand(new RestoreUACCommand(information.RestoreUACScriptPath));
+
processor.ProcessCommands();
});
}