Skip to content

Commit

Permalink
Add reading profile from Group Policy.
Browse files Browse the repository at this point in the history
  • Loading branch information
rinrab committed Dec 27, 2023
1 parent f99d14b commit ec11399
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions AOVpnManager/MinimalEventSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Diagnostics.Tracing;
using System;

namespace AOVpnManager
{
Expand All @@ -23,6 +24,12 @@ public void Exception(string message, string stackTrace)
WriteEvent(3, message, stackTrace);
}

[Event(4, Level = EventLevel.Informational, Channel = EventChannel.Operational, Message = "Profile change detected: {0}")]
public void ProfileChanged(string profile)
{
WriteEvent(4, profile);
}

public static MinimalEventSource Log = new MinimalEventSource();
}
}
23 changes: 20 additions & 3 deletions AOVpnManager/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Win32;
using System;

namespace AOVpnManager
{
Expand All @@ -11,9 +12,9 @@ static int Main(string[] args)

try
{
Console.WriteLine("Hello, world!");
string profile = GetProfile() ?? throw new Exception("Profile not found.");

throw new Exception("hello world");
MinimalEventSource.Log.ProfileChanged(profile);
}
catch (Exception ex)
{
Expand All @@ -26,5 +27,21 @@ static int Main(string[] args)

return exitCode;
}

static string GetProfile()
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Policies\AOVpnManager"))
{
string[] str = (string[])key?.GetValue("Profile");
if (str != null)
{
return string.Join("\n", str);
}
else
{
return null;
}
}
}
}
}

0 comments on commit ec11399

Please sign in to comment.