🟣 C# / .NET 6+
Backup Pointing Devices to JSON (C#)
Snapshots Pointing Devices (Win32_PointingDevice) to a timestamped JSON file via System.Management and System.Text.Json.
BackupPointingDeviceListToJson.cs
// BackupPointingDeviceListToJson.cs
//
// Snapshots Pointing Devices (Win32_PointingDevice) to a timestamped JSON file.
//
// Requires the System.Management package:
// dotnet new console -o BackupPointingDevice
// dotnet add package System.Management
// (replace the generated Program.cs with this file, then dotnet run)
using System;
using System.Collections.Generic;
using System.IO;
using System.Management;
using System.Text.Json;
var searcher = new ManagementObjectSearcher("SELECT Name, Manufacturer, NumberOfButtons FROM Win32_PointingDevice");
var results = new List<Dictionary<string, object?>>();
foreach (ManagementObject item in searcher.Get())
{
var row = new Dictionary<string, object?>();
row["Name"] = item["Name"];
row["Manufacturer"] = item["Manufacturer"];
row["NumberOfButtons"] = item["NumberOfButtons"];
results.Add(row);
}
string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss");
string outPath = $"pointingdevice-snapshot_{timestamp}.json";
File.WriteAllText(outPath, JsonSerializer.Serialize(results, new JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine($"Snapshot of Pointing Devices ({results.Count} items) saved to {outPath}");