Skip to content

Commit c60e155

Browse files
committed
.
1 parent 38543a0 commit c60e155

File tree

5 files changed

+86
-44
lines changed

5 files changed

+86
-44
lines changed
Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
using System.DirectoryServices;
1+
using System;
2+
using System.DirectoryServices;
23
using System.Security.Principal;
4+
using System.Threading.Tasks;
35
using System.Timers;
46

57
namespace SuperLauncher
68
{
79
public static class CredentialExpirationService
810
{
911
private static Timer Timer = new();
12+
public static DateTime ExpirationDate = DateTime.MaxValue;
1013
public static void Initialize()
1114
{
1215
Timer.Elapsed += CheckExpiration;
@@ -17,20 +20,35 @@ public static void Initialize()
1720
}
1821
public static void CheckExpiration(object s = null, object e = null)
1922
{
20-
DirectorySearcher ds = new();
21-
ds.SearchScope = SearchScope.Base;
22-
ds.PropertiesToLoad.Clear();
23-
ds.PropertiesToLoad.Add("maxPwdAge");
24-
ds.Filter = "";
25-
SearchResult root = ds.FindOne();
26-
ds.SearchScope = SearchScope.Subtree;
27-
ds.PropertiesToLoad.Clear();
28-
ds.PropertiesToLoad.Add("pwdLastSet");
29-
ds.Filter = "(objectSid=" + WindowsIdentity.GetCurrent().User.Value + ")";
30-
SearchResult user = ds.FindOne();
31-
32-
33-
//Found user and found policy, do work here
23+
Task.Run(() => {
24+
try
25+
{
26+
DirectorySearcher ds = new();
27+
ds.SearchScope = SearchScope.Base;
28+
ds.PropertiesToLoad.Clear();
29+
ds.PropertiesToLoad.Add("maxPwdAge");
30+
ds.Filter = "";
31+
SearchResult root = ds.FindOne();
32+
ds.SearchScope = SearchScope.Subtree;
33+
ds.PropertiesToLoad.Clear();
34+
ds.PropertiesToLoad.Add("userAccountControl");
35+
ds.PropertiesToLoad.Add("pwdLastSet");
36+
ds.Filter = "(objectSid=" + WindowsIdentity.GetCurrent().User.Value + ")";
37+
SearchResult user = ds.FindOne();
38+
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
39+
DateTime ExpirationDate = DateTime.FromFileTime((long)user.Properties["pwdLastSet"][0]);
40+
TimeSpan maxPwdAge = TimeSpan.FromMicroseconds((long)root.Properties["maxPwdAge"][0] / 10 * -1);
41+
42+
}
43+
catch
44+
{
45+
//Just give up
46+
}
47+
});
3448
}
49+
//private static datetime convertfromadtime()
50+
//{
51+
52+
//}
3553
}
3654
}

SuperLauncher/ModernLauncher.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<Grid Background="{DynamicResource AcrylicNoise}">
4444
<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" />
4545
<Label Content="Super Launcher" Foreground="{DynamicResource TextColorBrush}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="29,0,0,0" Width="94" />
46-
<Label x:Name="ElevateUser" Content="domain\user" Foreground="{DynamicResource TextColorBrush}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,30,0" Focusable="True" WindowChrome.IsHitTestVisibleInChrome="True"/>
46+
<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"/>
4747
<Label x:Name="ElevateIcon" Content="" Foreground="{DynamicResource TextColorBrush}" FontFamily="{DynamicResource Icons}" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="16" Margin="0,0,5,0" />
4848
</Grid>
4949
</Border>

SuperLauncher/ModernLauncher.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static DpiScale DPI
2424
private WindowInteropHelper WIH;
2525
private uint ShowSuperLauncherMessage = Win32Interop.RegisterWindowMessage("ShowSuperLauncher");
2626
private HwndSource HWND;
27+
private ModernLauncherBadge ExpirationBadge = null;
2728
private readonly DoubleAnimation RenderBoostAnimation = new()
2829
{
2930
Duration = TimeSpan.FromSeconds(0.5),
@@ -284,5 +285,14 @@ private void BtnAdd_Click(object sender, RoutedEventArgs e)
284285
((ModernLauncher)Program.ModernApplication.MainWindow).MLI.PopulateIcons();
285286
((ModernLauncher)Program.ModernApplication.MainWindow).OpenWindow();
286287
}
288+
private void ElevateUser_MouseEnter(object sender, MouseEventArgs e)
289+
{
290+
ExpirationBadge = new("Test");
291+
ExpirationBadge.Show();
292+
}
293+
private void ElevateUser_MouseLeave(object sender, MouseEventArgs e)
294+
{
295+
if (ExpirationBadge != null) ExpirationBadge.Close();
296+
}
287297
}
288298
}

SuperLauncher/ModernLauncherBadge.xaml.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,16 @@ namespace SuperLauncher
88
/// </summary>
99
public partial class ModernLauncherBadge : Window
1010
{
11-
private readonly int X, Y = 0;
12-
private readonly string Text;
13-
public ModernLauncherBadge(string Text, int X = 0, int Y = 0)
11+
public ModernLauncherBadge(string Text)
1412
{
15-
this.X = X;
16-
this.Y = Y;
17-
this.Text = Text;
1813
InitializeComponent();
14+
LabelText.Content = Text;
1915
}
2016
private void Label_Initialized(object sender, EventArgs e)
2117
{
22-
LabelText.Content = Text;
23-
if (X == 0 && Y == 0)
24-
{
25-
Win32Interop.GetCursorPos(out Win32Interop.POINT point);
26-
Top = ModernLauncher.DPI.ScalePixelsDown(point.y);
27-
Left = ModernLauncher.DPI.ScalePixelsDown(point.x);
28-
}
18+
Win32Interop.GetCursorPos(out Win32Interop.POINT point);
19+
Top = ModernLauncher.DPI.ScalePixelsDown(point.y);
20+
Left = ModernLauncher.DPI.ScalePixelsDown(point.x) - Width;
2921
}
3022
}
3123
}

SuperLauncher/Settings.cs

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ class SettingsDefault
1313
private readonly string configDir = Path.Combine(@"C:\Users\Public\Documents\Below Average\Super Launcher\", RunAsHelper.GetOriginalInvokerDomain(), RunAsHelper.GetOriginalInvokerUserName());
1414
public string configPath = Path.Combine(@"C:\Users\Public\Documents\Below Average\Super Launcher\", RunAsHelper.GetOriginalInvokerDomain(), RunAsHelper.GetOriginalInvokerUserName(), "SuperLauncherConfig.xml");
1515
public XmlDocument XDoc = new();
16+
public XmlDocument XDocDefault = new();
17+
private string DefaultXML =
18+
"<!-- Super Launcher Config File -->" +
19+
"<SuperLauncher>" +
20+
" <AutoElevate>false</AutoElevate>" +
21+
" <AutoRunAsDomain></AutoRunAsDomain>" +
22+
" <AutoRunAsUser></AutoRunAsUser>" +
23+
" <RememberMe>false</RememberMe>" +
24+
" <UseLegacyUI>false</UseLegacyUI>" +
25+
" <AppList>" +
26+
" <App>C:\\Windows\\System32\\cmd.exe</App>" +
27+
" </AppList>" +
28+
" <Width>390</Width>" +
29+
" <Height>230</Height>" +
30+
" <CredentialExpirationWarningDays>7</CredentialExpirationWarningDays>" +
31+
"</SuperLauncher>";
1632
public bool AutoElevate
1733
{
1834
get
@@ -90,10 +106,28 @@ public int Width
90106
Write("Width", value);
91107
}
92108
}
109+
public int CredentialExpirationWarningDays
110+
{
111+
get
112+
{
113+
return ReadInt("CredentialExpirationWarningDays");
114+
}
115+
set
116+
{
117+
Write("CredentialExpirationWarningDays", value);
118+
}
119+
}
93120
public string Read(string NodeName)
94121
{
95122
XmlNode node = XDoc.SelectSingleNode("/SuperLauncher/" + NodeName);
96-
if (node == null) return null;
123+
if (node == null)
124+
{
125+
node = XDocDefault.SelectSingleNode("/SuperLauncher/" + NodeName);
126+
XmlNode newNode = XDoc.CreateElement(NodeName);
127+
newNode.InnerXml = node.InnerXml;
128+
XDoc.SelectSingleNode("/SuperLauncher").AppendChild(newNode);
129+
if (node == null) return null;
130+
}
97131
return node.InnerText;
98132
}
99133
public bool ReadBool(string NodeName)
@@ -140,26 +174,14 @@ public AppListStringCollection FileList
140174
}
141175
public SettingsDefault()
142176
{
177+
XDocDefault.InnerXml = DefaultXML;
143178
if (File.Exists(configPath))
144179
{
145180
XDoc.Load(configPath);
146181
}
147182
else
148183
{
149-
XDoc.InnerXml =
150-
"<!-- Super Launcher Config File -->" +
151-
"<SuperLauncher>" +
152-
" <AutoElevate>false</AutoElevate>" +
153-
" <AutoRunAsDomain></AutoRunAsDomain>" +
154-
" <AutoRunAsUser></AutoRunAsUser>" +
155-
" <RememberMe>false</RememberMe>" +
156-
" <UseLegacyUI>false</UseLegacyUI>" +
157-
" <AppList>" +
158-
" <App>C:\\Windows\\System32\\cmd.exe</App>" +
159-
" </AppList>" +
160-
" <Width>390</Width>" +
161-
" <Height>230</Height>" +
162-
"</SuperLauncher>";
184+
XDoc.InnerXml = XDocDefault.InnerXml;
163185
}
164186
}
165187
public void Save()

0 commit comments

Comments
 (0)