Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Jul 9, 2024
1 parent 38543a0 commit c60e155
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 44 deletions.
48 changes: 33 additions & 15 deletions SuperLauncher/CredentialExpirationService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System.DirectoryServices;
using System;
using System.DirectoryServices;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Timers;

namespace SuperLauncher
{
public static class CredentialExpirationService
{
private static Timer Timer = new();
public static DateTime ExpirationDate = DateTime.MaxValue;
public static void Initialize()
{
Timer.Elapsed += CheckExpiration;
Expand All @@ -17,20 +20,35 @@ public static void Initialize()
}
public static void CheckExpiration(object s = null, object e = null)
{
DirectorySearcher ds = new();
ds.SearchScope = SearchScope.Base;
ds.PropertiesToLoad.Clear();
ds.PropertiesToLoad.Add("maxPwdAge");
ds.Filter = "";
SearchResult root = ds.FindOne();
ds.SearchScope = SearchScope.Subtree;
ds.PropertiesToLoad.Clear();
ds.PropertiesToLoad.Add("pwdLastSet");
ds.Filter = "(objectSid=" + WindowsIdentity.GetCurrent().User.Value + ")";
SearchResult user = ds.FindOne();


//Found user and found policy, do work here
Task.Run(() => {
try
{
DirectorySearcher ds = new();
ds.SearchScope = SearchScope.Base;
ds.PropertiesToLoad.Clear();
ds.PropertiesToLoad.Add("maxPwdAge");
ds.Filter = "";
SearchResult root = ds.FindOne();
ds.SearchScope = SearchScope.Subtree;
ds.PropertiesToLoad.Clear();
ds.PropertiesToLoad.Add("userAccountControl");
ds.PropertiesToLoad.Add("pwdLastSet");
ds.Filter = "(objectSid=" + WindowsIdentity.GetCurrent().User.Value + ")";
SearchResult user = ds.FindOne();
bool pwdNeverExpires = (((int)user.Properties["userAccountControl"][0]) & 0x00010000) == 0x00010000; //https://learn.microsoft.com/en-us/windows/win32/api/iads/ne-iads-ads_user_flag_enum
DateTime ExpirationDate = DateTime.FromFileTime((long)user.Properties["pwdLastSet"][0]);
TimeSpan maxPwdAge = TimeSpan.FromMicroseconds((long)root.Properties["maxPwdAge"][0] / 10 * -1);

}
catch
{
//Just give up
}
});
}
//private static datetime convertfromadtime()
//{

//}
}
}
2 changes: 1 addition & 1 deletion SuperLauncher/ModernLauncher.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Grid Background="{DynamicResource AcrylicNoise}">
<Label HorizontalAlignment="Left" Foreground="{DynamicResource TextColorBrush}" Margin="4,3,0,2" Width="26" Content="0" FontSize="16" FontFamily="{DynamicResource SLIcons}" RenderTransformOrigin="0.471,0.46" />
<Label Content="Super Launcher" Foreground="{DynamicResource TextColorBrush}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="29,0,0,0" Width="94" />
<Label x:Name="ElevateUser" Content="domain\user" Foreground="{DynamicResource TextColorBrush}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,30,0" Focusable="True" WindowChrome.IsHitTestVisibleInChrome="True"/>
<Label x:Name="ElevateUser" Content="domain\user" Foreground="{DynamicResource TextColorBrush}" MouseEnter="ElevateUser_MouseEnter" MouseLeave="ElevateUser_MouseLeave" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,30,0" Focusable="True" WindowChrome.IsHitTestVisibleInChrome="True"/>
<Label x:Name="ElevateIcon" Content="" Foreground="{DynamicResource TextColorBrush}" FontFamily="{DynamicResource Icons}" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="16" Margin="0,0,5,0" />
</Grid>
</Border>
Expand Down
10 changes: 10 additions & 0 deletions SuperLauncher/ModernLauncher.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static DpiScale DPI
private WindowInteropHelper WIH;
private uint ShowSuperLauncherMessage = Win32Interop.RegisterWindowMessage("ShowSuperLauncher");
private HwndSource HWND;
private ModernLauncherBadge ExpirationBadge = null;
private readonly DoubleAnimation RenderBoostAnimation = new()
{
Duration = TimeSpan.FromSeconds(0.5),
Expand Down Expand Up @@ -284,5 +285,14 @@ private void BtnAdd_Click(object sender, RoutedEventArgs e)
((ModernLauncher)Program.ModernApplication.MainWindow).MLI.PopulateIcons();
((ModernLauncher)Program.ModernApplication.MainWindow).OpenWindow();
}
private void ElevateUser_MouseEnter(object sender, MouseEventArgs e)
{
ExpirationBadge = new("Test");
ExpirationBadge.Show();
}
private void ElevateUser_MouseLeave(object sender, MouseEventArgs e)
{
if (ExpirationBadge != null) ExpirationBadge.Close();
}
}
}
18 changes: 5 additions & 13 deletions SuperLauncher/ModernLauncherBadge.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ namespace SuperLauncher
/// </summary>
public partial class ModernLauncherBadge : Window
{
private readonly int X, Y = 0;
private readonly string Text;
public ModernLauncherBadge(string Text, int X = 0, int Y = 0)
public ModernLauncherBadge(string Text)
{
this.X = X;
this.Y = Y;
this.Text = Text;
InitializeComponent();
LabelText.Content = Text;
}
private void Label_Initialized(object sender, EventArgs e)
{
LabelText.Content = Text;
if (X == 0 && Y == 0)
{
Win32Interop.GetCursorPos(out Win32Interop.POINT point);
Top = ModernLauncher.DPI.ScalePixelsDown(point.y);
Left = ModernLauncher.DPI.ScalePixelsDown(point.x);
}
Win32Interop.GetCursorPos(out Win32Interop.POINT point);
Top = ModernLauncher.DPI.ScalePixelsDown(point.y);
Left = ModernLauncher.DPI.ScalePixelsDown(point.x) - Width;
}
}
}
52 changes: 37 additions & 15 deletions SuperLauncher/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ class SettingsDefault
private readonly string configDir = Path.Combine(@"C:\Users\Public\Documents\Below Average\Super Launcher\", RunAsHelper.GetOriginalInvokerDomain(), RunAsHelper.GetOriginalInvokerUserName());
public string configPath = Path.Combine(@"C:\Users\Public\Documents\Below Average\Super Launcher\", RunAsHelper.GetOriginalInvokerDomain(), RunAsHelper.GetOriginalInvokerUserName(), "SuperLauncherConfig.xml");
public XmlDocument XDoc = new();
public XmlDocument XDocDefault = new();
private string DefaultXML =
"<!-- Super Launcher Config File -->" +
"<SuperLauncher>" +
" <AutoElevate>false</AutoElevate>" +
" <AutoRunAsDomain></AutoRunAsDomain>" +
" <AutoRunAsUser></AutoRunAsUser>" +
" <RememberMe>false</RememberMe>" +
" <UseLegacyUI>false</UseLegacyUI>" +
" <AppList>" +
" <App>C:\\Windows\\System32\\cmd.exe</App>" +
" </AppList>" +
" <Width>390</Width>" +
" <Height>230</Height>" +
" <CredentialExpirationWarningDays>7</CredentialExpirationWarningDays>" +
"</SuperLauncher>";
public bool AutoElevate
{
get
Expand Down Expand Up @@ -90,10 +106,28 @@ public int Width
Write("Width", value);
}
}
public int CredentialExpirationWarningDays
{
get
{
return ReadInt("CredentialExpirationWarningDays");
}
set
{
Write("CredentialExpirationWarningDays", value);
}
}
public string Read(string NodeName)
{
XmlNode node = XDoc.SelectSingleNode("/SuperLauncher/" + NodeName);
if (node == null) return null;
if (node == null)
{
node = XDocDefault.SelectSingleNode("/SuperLauncher/" + NodeName);
XmlNode newNode = XDoc.CreateElement(NodeName);
newNode.InnerXml = node.InnerXml;
XDoc.SelectSingleNode("/SuperLauncher").AppendChild(newNode);
if (node == null) return null;
}
return node.InnerText;
}
public bool ReadBool(string NodeName)
Expand Down Expand Up @@ -140,26 +174,14 @@ public AppListStringCollection FileList
}
public SettingsDefault()
{
XDocDefault.InnerXml = DefaultXML;
if (File.Exists(configPath))
{
XDoc.Load(configPath);
}
else
{
XDoc.InnerXml =
"<!-- Super Launcher Config File -->" +
"<SuperLauncher>" +
" <AutoElevate>false</AutoElevate>" +
" <AutoRunAsDomain></AutoRunAsDomain>" +
" <AutoRunAsUser></AutoRunAsUser>" +
" <RememberMe>false</RememberMe>" +
" <UseLegacyUI>false</UseLegacyUI>" +
" <AppList>" +
" <App>C:\\Windows\\System32\\cmd.exe</App>" +
" </AppList>" +
" <Width>390</Width>" +
" <Height>230</Height>" +
"</SuperLauncher>";
XDoc.InnerXml = XDocDefault.InnerXml;
}
}
public void Save()
Expand Down

0 comments on commit c60e155

Please sign in to comment.