Skip to content

Commit 98a0a90

Browse files
committed
Add Windows update install feature
1 parent d769fd5 commit 98a0a90

9 files changed

+84
-4
lines changed

App.config

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
<setting name="Scripts_FolderURI" serializeAs="String">
4040
<value>C:\HAC\scripts\</value>
4141
</setting>
42+
<setting name="Tools_FolderURI" serializeAs="String">
43+
<value>C:\Program Files\XRFAgent\tools\</value>
44+
</setting>
4245
</XRFAgent.Properties.Settings>
4346
</applicationSettings>
4447
</configuration>

Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.10")]
36-
[assembly: AssemblyFileVersion("1.0.0.10")]
35+
[assembly: AssemblyVersion("1.0.0.11")]
36+
[assembly: AssemblyFileVersion("1.0.0.11")]

Properties/Settings.Designer.cs

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Properties/Settings.settings

+3
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
<Setting Name="Scripts_FolderURI" Type="System.String" Scope="Application">
1212
<Value Profile="(Default)">C:\HAC\scripts\</Value>
1313
</Setting>
14+
<Setting Name="Tools_FolderURI" Type="System.String" Scope="Application">
15+
<Value Profile="(Default)">C:\Program Files\XRFAgent\tools\</Value>
16+
</Setting>
1417
</Settings>
1518
</SettingsFile>

XRFAgent.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<UpdatePeriodically>false</UpdatePeriodically>
2626
<UpdateRequired>false</UpdateRequired>
2727
<MapFileExtensions>true</MapFileExtensions>
28-
<ApplicationRevision>10</ApplicationRevision>
28+
<ApplicationRevision>11</ApplicationRevision>
2929
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
3030
<UseApplicationTrust>false</UseApplicationTrust>
3131
<BootstrapperEnabled>true</BootstrapperEnabled>

docs/ErrorCodes.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
6021 - Update check failed
1010
6022 - Update failed
1111
6023 - Update starting (informational)
12+
6024 - Tool installation failed
1213

1314
6031 - External process start error
1415
6032 - Registry access error
1516

17+
6041 - Windows Update error
18+
6042 - Windows Update results (informational)
19+
1620
6051 - Detected new software installed (informational)
1721
6052 - Truncated installed software inventory (informational)

modCommand.cs

+15
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ public static void Handle(string inputCommand, string inputSource, string reques
6363
outputResponse = "Updating"; break;
6464
}
6565
break;
66+
case "windows":
67+
result = modSystem.InstallWindowsUpdates();
68+
switch (result)
69+
{
70+
case 0:
71+
outputResponse = "Update successful"; break;
72+
case -1:
73+
case 31:
74+
outputResponse = "Update error"; break;
75+
case 3010:
76+
outputResponse = "Reboot required"; break;
77+
default:
78+
outputResponse = "Updating"; break;
79+
}
80+
break;
6681
default: break;
6782
}
6883
break;

modSystem.cs

+29
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,35 @@ public static string GetSystemDetails()
181181
}
182182
}
183183

184+
public static int InstallWindowsUpdates()
185+
{
186+
try
187+
{
188+
if (File.Exists(Properties.Settings.Default.Tools_FolderURI + "WindowsUpdatePush.exe") == false)
189+
{
190+
int installResult = modUpdate.InstallWindowsUpdatePush();
191+
if (installResult == -1)
192+
{
193+
return -1;
194+
}
195+
}
196+
Process UpdateRunner = new Process();
197+
UpdateRunner.StartInfo.UseShellExecute = false;
198+
UpdateRunner.StartInfo.RedirectStandardOutput = true;
199+
UpdateRunner.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
200+
UpdateRunner.StartInfo.FileName = Properties.Settings.Default.Tools_FolderURI + "WindowsUpdatePush.exe";
201+
UpdateRunner.Start();
202+
UpdateRunner.WaitForExit();
203+
modLogging.LogEvent(UpdateRunner.StandardOutput.ReadToEnd(), EventLogEntryType.Information, 6042);
204+
return UpdateRunner.ExitCode;
205+
}
206+
catch(Exception err)
207+
{
208+
modLogging.LogEvent("Windows Update error: " + err.Message, EventLogEntryType.Error, 6041);
209+
return -1;
210+
}
211+
}
212+
184213
/// <summary>
185214
/// Reboots the host computer
186215
/// </summary>

modUpdate.cs

+17
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ public static int UpdateAgent()
9999
return updateNeeded;
100100
}
101101

102+
public static int InstallWindowsUpdatePush()
103+
{
104+
try
105+
{
106+
Directory.CreateDirectory(Properties.Settings.Default.Tools_FolderURI);
107+
UpdateDownloadClient.DownloadFile(Properties.Settings.Default.Update_SourceURI + "windowsupdatepush.zip", Properties.Settings.Default.Tools_FolderURI + "windowsupdatepush.zip");
108+
ZipFile.ExtractToDirectory(Properties.Settings.Default.Tools_FolderURI + "windowsupdatepush.zip", Properties.Settings.Default.Tools_FolderURI);
109+
File.Delete(Properties.Settings.Default.Tools_FolderURI + "windowsupdatepush.zip");
110+
return 0;
111+
}
112+
catch (Exception err)
113+
{
114+
modLogging.LogEvent(err.Message, EventLogEntryType.Error, 6024);
115+
return -1;
116+
}
117+
}
118+
102119
public static int Autoupdate()
103120
{
104121
if (modDatabase.GetConfig("Update_Autoupdate") == "enabled")

0 commit comments

Comments
 (0)