Skip to content

Commit 516ae25

Browse files
committed
Command to run Ookla speedtest
1 parent 98d8b9c commit 516ae25

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

docs/ErrorCodes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@
2424
6051 - Detected new software installed (informational)
2525
6052 - Truncated installed software inventory (informational)
2626

27-
6061 - Detected disk error
27+
6061 - Detected disk error
28+
29+
6071 - Speed test error
30+
6072 - Speed test results (informational)

modCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public static void Handle(string inputCommand, string inputSource, string reques
5050
if (inputData[1] == "rekey" && inputData[2].StartsWith("https://")) { outputResponse = modSync.RemoteRekey(inputData[2], inputData[3]); } break;
5151
case "reset" when inputData.Length == 3:
5252
if (inputData[1] == "installed" && inputData[2] == "software") { outputResponse = modSystem.ResetInstalledSoftware(); } break;
53+
case "run" when inputData.Length == 2:
54+
if (inputData[1] == "speedtest") { outputResponse = "Running speed test"; modSystem.RunSpeedTest(); } break;
5355
case "shutdown" when inputData.Length == 2:
5456
if (inputData[1] == "host") { outputResponse = modSystem.ShutdownHost(); } break;
5557
case "update" when inputData.Length == 2:

modSystem.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ public static string GetSystemDetails()
196196
}
197197
}
198198

199+
/// <summary>
200+
/// Installs updates for Windows, installs WindowsUpdatePush tool if it is not present
201+
/// </summary>
202+
/// <returns>(int) Return code</returns>
199203
public static int InstallWindowsUpdates()
200204
{
201205
try
@@ -225,6 +229,41 @@ public static int InstallWindowsUpdates()
225229
}
226230
}
227231

232+
/// <summary>
233+
/// Runs Ookla Speedtest, installs Speedtest CLI tool if it is not present
234+
/// </summary>
235+
/// <returns></returns>
236+
public static int RunSpeedTest()
237+
{
238+
try
239+
{
240+
if (File.Exists(Properties.Settings.Default.Tools_FolderURI + "speedtest.exe") == false)
241+
{
242+
int installResult = modUpdate.InstallOoklaSpeedtest();
243+
if (installResult == -1)
244+
{
245+
return -1;
246+
}
247+
}
248+
Process SpeedTestRunner = new Process();
249+
SpeedTestRunner.StartInfo.UseShellExecute = false;
250+
SpeedTestRunner.StartInfo.RedirectStandardOutput = true;
251+
SpeedTestRunner.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
252+
SpeedTestRunner.StartInfo.FileName = Properties.Settings.Default.Tools_FolderURI + "speedtest.exe";
253+
SpeedTestRunner.StartInfo.Arguments = "-f json --accept-license";
254+
SpeedTestRunner.Start();
255+
SpeedTestRunner.WaitForExit();
256+
string speedJson = SpeedTestRunner.StandardOutput.ReadToEnd();
257+
modLogging.LogEvent("Speed test results: " + speedJson, EventLogEntryType.Information, 6072);
258+
return SpeedTestRunner.ExitCode;
259+
}
260+
catch(Exception err)
261+
{
262+
modLogging.LogEvent("Speed test error: " + err.Message, EventLogEntryType.Error, 6071);
263+
return -1;
264+
}
265+
}
266+
228267
/// <summary>
229268
/// Reboots the host computer
230269
/// </summary>

0 commit comments

Comments
 (0)