Files
SpdUp/Services/ServiceManagementService.cs
Phil-icyou 19ba425e79 Initial commit: SpdUp Windows Gaming Booster v1.0.0
- .NET 8 WPF app with full MVVM architecture
- One-click boost: CPU, RAM, GPU, network, services, timer resolution
- Real-time system monitor (LibreHardwareMonitor)
- Auto game detection (30+ games)
- RAM optimizer with kernel-level cleanup
- Network optimizer (TCP registry tweaks)
- Service manager, process manager, shader cache cleaner
- Desktop widget overlay
- Debug log viewer
- Custom dark gaming theme with trans pride colors
- 84 unit tests (xUnit)
- Inno Setup installer script
- Landing page website
2026-03-08 17:34:45 +01:00

97 lines
3.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Diagnostics;
using System.ServiceProcess;
using SpdUp.Core;
using SpdUp.Models;
namespace SpdUp.Services;
/// <summary>
/// Service management: list, stop, start Windows services.
/// </summary>
public static class ServiceManagementService
{
/// <summary>
/// Non-critical services commonly stopped for gaming.
/// </summary>
public static readonly Dictionary<string, string> KnownNonCriticalServices = new()
{
["SysMain"] = "Superfetch / SysMain pre-loads apps into RAM",
["WSearch"] = "Windows Search indexing",
["DiagTrack"] = "Connected User Experiences and Telemetry",
["TabletInputService"] = "Touch Keyboard and Handwriting Panel",
["MapsBroker"] = "Downloaded Maps Manager",
["PcaSvc"] = "Program Compatibility Assistant",
["wisvc"] = "Windows Insider Service",
["WbioSrvc"] = "Windows Biometric Service",
["Fax"] = "Fax service",
["XblAuthManager"] = "Xbox Live Auth Manager",
["XblGameSave"] = "Xbox Live Game Save",
["XboxNetApiSvc"] = "Xbox Live Networking Service",
};
public static List<ServiceEntry> GetServiceList(IEnumerable<string> serviceNames)
{
var entries = new List<ServiceEntry>();
foreach (var name in serviceNames)
{
try
{
using var sc = new ServiceController(name);
entries.Add(new ServiceEntry
{
ServiceName = sc.ServiceName,
DisplayName = sc.DisplayName,
Status = sc.Status.ToString(),
Description = KnownNonCriticalServices.GetValueOrDefault(name, "")
});
}
catch
{
entries.Add(new ServiceEntry
{
ServiceName = name,
DisplayName = name,
Status = "NotFound"
});
}
}
return entries;
}
public static bool StopService(string serviceName)
{
try
{
using var sc = new ServiceController(serviceName);
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(15));
Logger.Info($"Stopped service: {serviceName}");
return true;
}
}
catch (Exception ex) { Logger.Error($"Failed to stop {serviceName}", ex); }
return false;
}
public static bool StartService(string serviceName)
{
try
{
using var sc = new ServiceController(serviceName);
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(15));
Logger.Info($"Started service: {serviceName}");
return true;
}
}
catch (Exception ex) { Logger.Error($"Failed to start {serviceName}", ex); }
return false;
}
}