Skip to content

Commit

Permalink
Preliminary system data collection
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdtrekkie committed Jul 9, 2024
1 parent bb05f67 commit b8e43f2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions XRFAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
Expand Down
3 changes: 2 additions & 1 deletion modCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public static void Handle(string inputCommand, string inputSource, string reques
switch (inputData[0])
{
case "check" when inputData.Length == 3:
if (inputData[1] == "installed" && inputData[2] == "software") { outputResponse = modSystem.GetInstalledSoftware(); } break;
if (inputData[1] == "installed" && inputData[2] == "software") { outputResponse = modSystem.GetInstalledSoftware(); }
else if (inputData[1] == "system" && inputData[2] == "details") { outputResponse = modSystem.GetSystemDetails(); } break;
case "hac":
case "hacontroller":
string inputCommandTrimmed = inputCommand.Remove(0, inputData[0].Length + 1);
Expand Down
39 changes: 39 additions & 0 deletions modSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json;
using Microsoft.VisualBasic.Devices;
using Microsoft.Win32;

namespace XRFAgent
Expand Down Expand Up @@ -83,6 +84,44 @@ public static string ResetInstalledSoftware()
return GetInstalledSoftware();
}

/// <summary>
/// Collects some general system information
/// </summary>
/// <returns>(string) Result</returns>
public static string GetSystemDetails()
{
try
{
RegistryKey systemHardware = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\BIOS");
string moboManufacturer = systemHardware.GetValue("BaseBoardManufacturer").ToString();
modLogging.LogEvent("Mobo Manufacturer: " + moboManufacturer, EventLogEntryType.Information, 9999);
string moboProduct = systemHardware.GetValue("BaseBoardProduct").ToString();
modLogging.LogEvent("Mobo Product: " + moboProduct, EventLogEntryType.Information, 9999);
string compManufacturer = systemHardware.GetValue("SystemManufacturer").ToString();
modLogging.LogEvent("CSys Manufacturer: " + compManufacturer, EventLogEntryType.Information, 9999);
string compModel = systemHardware.GetValue("SystemProductName").ToString();
modLogging.LogEvent("CSys Model: " + compModel, EventLogEntryType.Information, 9999);

RegistryKey systemCPU = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0");
string processorName = systemCPU.GetValue("ProcessorNameString").ToString();
modLogging.LogEvent("Proc Name: " + processorName, EventLogEntryType.Information, 9999);
ComputerInfo VBCI = new ComputerInfo();
string physicalMemory = VBCI.TotalPhysicalMemory.ToString();
modLogging.LogEvent("Phys Memory: " + physicalMemory, EventLogEntryType.Information, 9999);

string machineName = Environment.MachineName.ToString();
int uptimeMilliseconds = Environment.TickCount;
string logicalDrives = String.Join(", ", Environment.GetLogicalDrives()).TrimEnd(',', ' ');

return "System details in event log";
}
catch (Exception err)
{
modLogging.LogEvent("Unable to get registry information: " + err.Message + "\n\n" + err.StackTrace, EventLogEntryType.Error, 6032);
return "Registry error";
}
}

/// <summary>
/// Gets a full Windows build number from the registry
/// </summary>
Expand Down

0 comments on commit b8e43f2

Please sign in to comment.