Skip to content

Commit

Permalink
Add Windows update install feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdtrekkie committed Aug 4, 2024
1 parent d769fd5 commit 98a0a90
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 4 deletions.
3 changes: 3 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<setting name="Scripts_FolderURI" serializeAs="String">
<value>C:\HAC\scripts\</value>
</setting>
<setting name="Tools_FolderURI" serializeAs="String">
<value>C:\Program Files\XRFAgent\tools\</value>
</setting>
</XRFAgent.Properties.Settings>
</applicationSettings>
</configuration>
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.10")]
[assembly: AssemblyFileVersion("1.0.0.10")]
[assembly: AssemblyVersion("1.0.0.11")]
[assembly: AssemblyFileVersion("1.0.0.11")]
11 changes: 10 additions & 1 deletion Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
<Setting Name="Scripts_FolderURI" Type="System.String" Scope="Application">
<Value Profile="(Default)">C:\HAC\scripts\</Value>
</Setting>
<Setting Name="Tools_FolderURI" Type="System.String" Scope="Application">
<Value Profile="(Default)">C:\Program Files\XRFAgent\tools\</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion XRFAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>10</ApplicationRevision>
<ApplicationRevision>11</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
4 changes: 4 additions & 0 deletions docs/ErrorCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
6021 - Update check failed
6022 - Update failed
6023 - Update starting (informational)
6024 - Tool installation failed

6031 - External process start error
6032 - Registry access error

6041 - Windows Update error
6042 - Windows Update results (informational)

6051 - Detected new software installed (informational)
6052 - Truncated installed software inventory (informational)
15 changes: 15 additions & 0 deletions modCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ public static void Handle(string inputCommand, string inputSource, string reques
outputResponse = "Updating"; break;
}
break;
case "windows":
result = modSystem.InstallWindowsUpdates();
switch (result)
{
case 0:
outputResponse = "Update successful"; break;
case -1:
case 31:
outputResponse = "Update error"; break;
case 3010:
outputResponse = "Reboot required"; break;
default:
outputResponse = "Updating"; break;
}
break;
default: break;
}
break;
Expand Down
29 changes: 29 additions & 0 deletions modSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,35 @@ public static string GetSystemDetails()
}
}

public static int InstallWindowsUpdates()
{
try
{
if (File.Exists(Properties.Settings.Default.Tools_FolderURI + "WindowsUpdatePush.exe") == false)
{
int installResult = modUpdate.InstallWindowsUpdatePush();
if (installResult == -1)
{
return -1;
}
}
Process UpdateRunner = new Process();
UpdateRunner.StartInfo.UseShellExecute = false;
UpdateRunner.StartInfo.RedirectStandardOutput = true;
UpdateRunner.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
UpdateRunner.StartInfo.FileName = Properties.Settings.Default.Tools_FolderURI + "WindowsUpdatePush.exe";
UpdateRunner.Start();
UpdateRunner.WaitForExit();
modLogging.LogEvent(UpdateRunner.StandardOutput.ReadToEnd(), EventLogEntryType.Information, 6042);
return UpdateRunner.ExitCode;
}
catch(Exception err)
{
modLogging.LogEvent("Windows Update error: " + err.Message, EventLogEntryType.Error, 6041);
return -1;
}
}

/// <summary>
/// Reboots the host computer
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions modUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ public static int UpdateAgent()
return updateNeeded;
}

public static int InstallWindowsUpdatePush()
{
try
{
Directory.CreateDirectory(Properties.Settings.Default.Tools_FolderURI);
UpdateDownloadClient.DownloadFile(Properties.Settings.Default.Update_SourceURI + "windowsupdatepush.zip", Properties.Settings.Default.Tools_FolderURI + "windowsupdatepush.zip");
ZipFile.ExtractToDirectory(Properties.Settings.Default.Tools_FolderURI + "windowsupdatepush.zip", Properties.Settings.Default.Tools_FolderURI);
File.Delete(Properties.Settings.Default.Tools_FolderURI + "windowsupdatepush.zip");
return 0;
}
catch (Exception err)
{
modLogging.LogEvent(err.Message, EventLogEntryType.Error, 6024);
return -1;
}
}

public static int Autoupdate()
{
if (modDatabase.GetConfig("Update_Autoupdate") == "enabled")
Expand Down

0 comments on commit 98a0a90

Please sign in to comment.