Compare commits
3
Commits
0098b49787
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dd9028db3 | ||
|
|
8c3f297b2c | ||
|
|
8b36e5ed18 |
No files matched your search
+1
-1
@@ -6,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>agent</AssemblyName>
|
||||
<RootNamespace>NetBoxWindowsAgent</RootNamespace>
|
||||
<Version>0.2.0</Version>
|
||||
<Version>0.2.2</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Management" Version="8.0.0" />
|
||||
|
||||
@@ -340,7 +340,7 @@ Path: C:\Program Files\NetBox Windows Agent
|
||||
File or folder: agent.exe
|
||||
Detection method: String (version)
|
||||
Operator: Greater than or equal to
|
||||
Value: 0.2.0 (the version of agent.exe, see agent.exe --version)
|
||||
Value: 0.2.2 (the version of agent.exe, see agent.exe --version)
|
||||
Associated with a 32-bit app on 64-bit clients: No
|
||||
```
|
||||
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@ dotnet publish (Join-Path $projectRoot 'NetBoxAgent.csproj') `
|
||||
-c $Configuration -r $Runtime --self-contained true `
|
||||
-p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true `
|
||||
-p:DebugType=None -p:DebugSymbols=false -o $output
|
||||
Write-Host "Erstellt: $output\agent.exe"
|
||||
Write-Host "Built: $output\agent.exe"
|
||||
|
||||
+20
-4
@@ -22,10 +22,26 @@ $syncTask = 'NetBox Windows Agent'
|
||||
$listenerTask = 'NetBox Windows Agent Listener'
|
||||
$firewallRule = 'NetBoxWindowsAgent'
|
||||
|
||||
$principalNow = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
||||
if (-not $principalNow.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||
throw 'install.ps1 must run as administrator or SYSTEM (PowerShell: "Run as administrator"; Intune: install behavior "System").'
|
||||
}
|
||||
|
||||
$sourceAgent = Join-Path $SourceDirectory 'agent.exe'
|
||||
$sourceConfig = Join-Path $SourceDirectory 'config.json'
|
||||
if (-not (Test-Path -LiteralPath $sourceAgent)) { throw 'agent.exe is missing in the source directory.' }
|
||||
if (-not (Test-Path -LiteralPath $sourceConfig)) { throw 'config.json is missing in the source directory.' }
|
||||
if (-not (Test-Path -LiteralPath $sourceAgent)) { throw "agent.exe is missing in the source directory $SourceDirectory." }
|
||||
if (-not (Test-Path -LiteralPath $sourceConfig)) { throw "config.json is missing in the source directory $SourceDirectory." }
|
||||
|
||||
# Copies a file, retrying while it is briefly locked (e.g. an antivirus scan of the new agent.exe).
|
||||
function Copy-WithRetry([string]$Source, [string]$Destination) {
|
||||
for ($attempt = 1; ; $attempt++) {
|
||||
try { Copy-Item -LiteralPath $Source -Destination $Destination -Force; return }
|
||||
catch [System.UnauthorizedAccessException], [System.IO.IOException] {
|
||||
if ($attempt -ge 10) { throw "Cannot write $Destination ($($_.Exception.Message)). Is agent.exe still running or blocked by an antivirus?" }
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($Schedule -ne 'DAILY') { throw "Only the schedule 'DAILY' is supported." }
|
||||
|
||||
$config = Get-Content -LiteralPath $sourceConfig -Raw | ConvertFrom-Json
|
||||
@@ -44,8 +60,8 @@ Get-Process -Name agent -ErrorAction SilentlyContinue |
|
||||
Start-Sleep -Milliseconds 500
|
||||
|
||||
New-Item -ItemType Directory -Path $InstallDirectory -Force | Out-Null
|
||||
Copy-Item -LiteralPath $sourceAgent -Destination (Join-Path $InstallDirectory 'agent.exe') -Force
|
||||
Copy-Item -LiteralPath $sourceConfig -Destination (Join-Path $InstallDirectory 'config.json') -Force
|
||||
Copy-WithRetry $sourceAgent (Join-Path $InstallDirectory 'agent.exe')
|
||||
Copy-WithRetry $sourceConfig (Join-Path $InstallDirectory 'config.json')
|
||||
$acl = Get-Acl $InstallDirectory
|
||||
$acl.SetAccessRuleProtection($true, $false)
|
||||
$administratorsSid = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')
|
||||
|
||||
@@ -24,7 +24,7 @@ internal static class HardwareCollector
|
||||
Strings(x, "IPAddress").Where(ip => !ip.StartsWith("169.254.")).ToList())).ToList();
|
||||
var memoryModules = Query("Win32_PhysicalMemory", "BankLabel", "DeviceLocator", "Manufacturer", "PartNumber", "SerialNumber", "Capacity")
|
||||
.Select(x => new MemoryInfo(
|
||||
string.IsNullOrWhiteSpace(S(x, "BankLabel")) ? S(x, "DeviceLocator") : S(x, "BankLabel"),
|
||||
MemorySlot(S(x, "DeviceLocator"), S(x, "BankLabel")),
|
||||
S(x, "Manufacturer"), S(x, "PartNumber"), S(x, "SerialNumber"), U(x, "Capacity"))).ToList();
|
||||
|
||||
return new HardwareInfo
|
||||
@@ -118,6 +118,13 @@ internal static class HardwareCollector
|
||||
using var searcher = new ManagementObjectSearcher($"SELECT {string.Join(',', fields)} FROM {cls}");
|
||||
foreach (ManagementBaseObject item in searcher.Get()) yield return item;
|
||||
}
|
||||
// BankLabel repeats per channel on many boards ("BANK 0" for channel A and B);
|
||||
// DeviceLocator ("ChannelA-DIMM0") is the unique slot name.
|
||||
private static string MemorySlot(string locator, string bank) =>
|
||||
string.IsNullOrWhiteSpace(locator) ? bank
|
||||
: string.IsNullOrWhiteSpace(bank) || locator.Contains(bank, StringComparison.OrdinalIgnoreCase) ? locator
|
||||
: $"{locator} ({bank})";
|
||||
|
||||
private static string S(ManagementBaseObject x, string key) => Convert.ToString(x[key])?.Trim() ?? "";
|
||||
private static ulong U(ManagementBaseObject x, string key) => ulong.TryParse(Convert.ToString(x[key]), out var n) ? n : 0;
|
||||
private static List<string> Strings(ManagementBaseObject x, string key) =>
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ namespace NetBoxWindowsAgent;
|
||||
|
||||
internal static class AgentInfo
|
||||
{
|
||||
public const string Version = "0.2.0";
|
||||
public const string Version = "0.2.2";
|
||||
public const int Protocol = 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user