2 Commits

Author SHA1 Message Date
dce789db94 Resolved device list and IP addresses not working via osqueryi.
Now also returning last boottime by doing bootup time and math from current time
2025-11-04 08:55:00 +08:00
cedf28199e Fix: Use AppData directory for log files to avoid permission errors
Issue: Application crashed when installed in Program Files due to
UnauthorizedAccessException when trying to write log files to the
installation directory.

Changes:
- SystemInfo.cs: Updated error logging to use LocalApplicationData/PSG-Oversight
- OsqueryService.cs: Added GetLogPath() helper method and updated all log writes
  to use user's AppData directory instead of current directory
- Added try-catch wrappers to silently handle any remaining logging failures

All log files now write to: %LOCALAPPDATA%\PSG-Oversight\

This fixes the startup crash reported in Event Viewer when running
the installed application.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 08:17:43 +08:00
4 changed files with 43 additions and 15 deletions

View File

@@ -1,9 +1,7 @@
{
"permissions": {
"allow": [
"Bash(dotnet build:*)",
"Bash(git add:*)",
"Bash(git commit -m \"$(cat <<''EOF''\nRelease v1.2.0: Integrate osquery for enhanced system information\n\nMajor Features:\n- Integrated osquery for comprehensive system information gathering\n- Added OsqueryService for executing SQL queries against system tables\n- Implemented Osquery Console tab for interactive SQL queries\n\nSystem Info Improvements:\n- Enhanced system info collection using osquery tables\n- Added support for multiple GPU detection\n- Improved memory detection with proper GB formatting\n- Fixed OS Architecture detection (x64/x86)\n- Better network interface detection (IPv4 only)\n- Human-readable timestamp formatting\n\nUI/UX Enhancements:\n- Added window resizing with corner drag support\n- Implemented dynamic window sizing (SizeToContent)\n- Added ScrollViewer for content overflow\n- Improved IP address formatting with bullet points\n- Added field labels to all system info displays\n- Set minimum/maximum window size constraints\n\nBug Fixes:\n- Fixed XAML StackPanel Spacing property issue\n- Merged duplicate MainWindow constructors\n- Fixed non-nullable field warnings\n- Fixed EventHandler nullability signatures\n- Removed redundant hostname/OS name fields\n- Fixed GPU registry query to detect all GPUs\n\n🤖 Generated with [Claude Code](https://claude.com/claude-code)\n\nCo-Authored-By: Claude <noreply@anthropic.com>\nEOF\n)\")"
"Bash(\"BuildDir\\bin\\Debug\\Assets\\osqueryi.exe\" --json \"SELECT datetime((SELECT CAST(unix_time AS INTEGER) FROM time) - total_seconds, ''unixepoch'') as boot_time FROM uptime;\")"
],
"deny": [],
"ask": []

View File

@@ -9,7 +9,8 @@
<UseWPF>true</UseWPF>
<StartupObject>LD_SysInfo.App</StartupObject>
<ApplicationIcon>Assets\LDShortcut.ico</ApplicationIcon>
<OutputPath>C:\Users\Sonder\source\repos\psg-oversight-app\BuildDir\bin\Debug\net8.0-windows\</OutputPath>
<OutputPath>C:\Users\Sonder\source\repos\psg-oversight-app\BuildDir\bin\Debug\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<IncludeSatelliteAssembliesForPublish>false</IncludeSatelliteAssembliesForPublish>
<!-- 🔢 Version Info -->

View File

@@ -9,6 +9,13 @@ namespace LD_SysInfo.Services
{
public static class OsqueryService
{
private static string GetLogPath(string filename)
{
string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PSG-Oversight");
Directory.CreateDirectory(logDir);
return Path.Combine(logDir, filename);
}
private static string GetOsqueryPath()
{
var baseDir = AppContext.BaseDirectory;
@@ -16,7 +23,11 @@ namespace LD_SysInfo.Services
if (!File.Exists(path))
{
File.AppendAllText("osquery_error.log", $"[{DateTime.Now}] ❌ osqueryi.exe not found at {path}\n");
try
{
File.AppendAllText(GetLogPath("osquery_error.log"), $"[{DateTime.Now}] ❌ osqueryi.exe not found at {path}\n");
}
catch { /* Silently fail if we can't write logs */ }
throw new FileNotFoundException("osqueryi.exe not found", path);
}
@@ -42,8 +53,12 @@ namespace LD_SysInfo.Services
process.WaitForExit();
// Optional debug logging
File.AppendAllText("osquery_debug.log",
try
{
File.AppendAllText(GetLogPath("osquery_debug.log"),
$"[{DateTime.Now}] Ran query: {sql}\nOutput length: {output.Length}\n");
}
catch { /* Silently fail if we can't write logs */ }
return output;
}
@@ -69,8 +84,12 @@ namespace LD_SysInfo.Services
}
catch (Exception ex)
{
File.AppendAllText("osquery_error.log",
try
{
File.AppendAllText(GetLogPath("osquery_error.log"),
$"[{DateTime.Now}] ⚠️ JSON parse failed for query '{sql}': {ex.Message}\n");
}
catch { /* Silently fail if we can't write logs */ }
return new List<Dictionary<string, string>>();
}
}

View File

@@ -142,10 +142,10 @@ namespace LD_SysInfo
}
// ✅ Drives
info.Drives = OsqueryService.Query("SELECT device, size, free_space, type FROM logical_drives;")
info.Drives = OsqueryService.Query("SELECT device_id, size, free_space, type FROM logical_drives;")
.Select(d => new DriveInfoSummary
{
Name = d.GetValueOrDefault("device"),
Name = d.GetValueOrDefault("device_id"),
TotalSizeGB = d.ContainsKey("size") && double.TryParse(d["size"], out double size)
? Math.Round(size / (1024.0 * 1024.0 * 1024.0), 2) : 0,
FreeSpaceGB = d.ContainsKey("free_space") && double.TryParse(d["free_space"], out double free)
@@ -179,9 +179,9 @@ namespace LD_SysInfo
.Where(ni => !string.IsNullOrEmpty(ni.IpAddress))
.ToList();
// ✅ Last boot time
info.LastBootTime = OsqueryService.Query("SELECT datetime(boot_time, 'unixepoch') AS last_boot FROM uptime;")
.FirstOrDefault()?.GetValueOrDefault("last_boot");
// ✅ Last boot time - calculate from current time minus uptime
info.LastBootTime = OsqueryService.Query("SELECT datetime((SELECT CAST(unix_time AS INTEGER) FROM time) - total_seconds, 'unixepoch') as boot_time FROM uptime;")
.FirstOrDefault()?.GetValueOrDefault("boot_time");
// ✅ Installed apps (user + system)
info.InstalledApplications = OsqueryService.Query("SELECT name, version, publisher FROM programs;")
@@ -218,7 +218,17 @@ namespace LD_SysInfo
}
catch (Exception ex)
{
File.AppendAllText("osquery_error.log", $"[{DateTime.Now}] {ex}\n");
try
{
string logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PSG-Oversight");
Directory.CreateDirectory(logDir);
string logPath = Path.Combine(logDir, "osquery_error.log");
File.AppendAllText(logPath, $"[{DateTime.Now}] {ex}\n");
}
catch
{
// Silently fail if we can't write logs
}
}
return info;