Skip to content

Commit

Permalink
Collapses ADMX user/computer sections into one
Browse files Browse the repository at this point in the history
Moves warning message ADMX settings to its own policy
Fixes an issue where the warning window would show and hide itself in a loop
  • Loading branch information
ryannewington committed Mar 1, 2019
1 parent 3e59d33 commit 45fde7a
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 88 deletions.
4 changes: 2 additions & 2 deletions src/Lithnet.IdleLogoff/LogoffWarning.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions src/Lithnet.IdleLogoff/LogoffWarning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,14 @@ private void UpdateLabelText()
{
if (this.LogoffDateTime > DateTime.Now)
{
this.lbWarning.Text = string.Format("Your session has been idle for too long, and you will be logged out in {0} seconds. Move the mouse or press any key to cancel", (int) ((this.LogoffDateTime.Subtract(DateTime.Now)).TotalSeconds));
this.lbWarning.Text = string.Format(Settings.WarningMessage, (int) ((this.LogoffDateTime.Subtract(DateTime.Now)).TotalSeconds));
}
else
{
this.lbWarning.Text = "Your session has been idle for too long, and you will be logged out soon. Move the mouse or press any key to cancel";
this.lbWarning.Text = string.Empty;
}
}

private void LogoffWarning_MouseMove(object sender, MouseEventArgs e)
{
Trace.WriteLine("Hiding warning window on mouse move");
this.Hide();
}

private void LogoffWarning_KeyPress(object sender, KeyPressEventArgs e)
{
Trace.WriteLine("Hiding warning window on key press");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@
</description>
<resources>
<stringTable>
<string id="CAT_78275968_599A_4E3F_BAD6_07C70894AF09">IdleLogoff</string>
<string id="POL_978C1C26_0621_4860_A000_61A23A440151">Log off inactive users</string>
<string id="POL_F3930A2B-33F8-4CE6-B6AC-14F188507B77">Log off</string>
<string id="POL_D61A5346-B53C-42FB-99FF-6519F18B281C">Reboot</string>
<string id="POL_582D5654-4165-42D2-BF83-6A182FF67587">Shutdown</string>
<string id="cat_idle_logoff">IdleLogoff</string>
<string id="pol_enable_idle_logoff">Log off inactive users</string>
<string id="pol_show_warning_message">Show a warning message before logging off</string>
<string id="pol_show_warning_message_help">Shows a pop up notification informing the user of the number of seconds remaining before they are logged off.

You can optionally provide a custom message to show the user. Use {0} as a placeholder for the remaining seconds until logoff.
</string>
<string id="string_logoff">Log off</string>
<string id="string_reboot">Reboot</string>
<string id="string_shutdown">Shutdown</string>
<string id="SUPPORTED_WindowsVISTA">At least Microsoft Windows</string>
<string id="TS_SUPPORTED_WindowsXP">At least Microsoft Windows XP</string>
</stringTable>
<presentationTable>
<presentation id="POL_978C1C26_0621_4860_A000_61A23A440151">
<decimalTextBox refId="DXT_7E914D9D_203C_40DF_8C49_93B29308A6B2" defaultValue="60">Idle timeout (minutes)</decimalTextBox>
<decimalTextBox refId="DXT_34f51d8da07c479bae41dd8db061812f" defaultValue="0">Show a warning for before logging the user off (seconds before logoff)</decimalTextBox>
<checkBox refId="DXT_B357DAA7-0013-45D9-94DC-E91206837C29" defaultChecked="false">Ignore sleep prevention requests from applications such as media playback</checkBox>
<dropdownList refId="DXT_3E1833A6-D761-40B5-8BF9-5C03F320C86B" defaultItem ="0">Action</dropdownList>
<presentation id="pol_show_warning_message">
<decimalTextBox refId="txt_warning_period" defaultValue="0">Duration of warning message (seconds)</decimalTextBox>
<textBox refId="txt_warning_message">
<label>Warning message text</label>
<defaultValue>Your session has been idle for too long, and you will be logged out in {0} seconds</defaultValue>
</textBox>
</presentation>
<presentation id="POL_1D519699-D182-4B28-A489-1F7DE9DB6DE5">
<decimalTextBox refId="DXT_B29D2480-E131-4C23-B4D4-F55CAA13C2FF" defaultValue="60">Idle timeout (minutes)</decimalTextBox>
<decimalTextBox refId="DXT_8ab92f9f21e642dd9c343c1f185c8b4b" defaultValue="0">Show a warning for before logging the user off (seconds before logoff)</decimalTextBox>
<checkBox refId="DXT_CFF2EAC7-2034-47F9-B3CE-8D10C73FCA81" defaultChecked="false">Ignore sleep prevention requests from applications such as media playback</checkBox>
<dropdownList refId="DXT_6C79F5D5-6DB7-4194-BCB5-7CF6752263EA" defaultItem ="0">Action</dropdownList>
<presentation id="pol_enable_idle_logoff">
<decimalTextBox refId="txt_idle_limit" defaultValue="60">Idle timeout (minutes)</decimalTextBox>
<checkBox refId="ck_ignore_display_requested" defaultChecked="false">Ignore sleep prevention requests from applications such as media playback</checkBox>
<dropdownList refId="dd_idle_action" defaultItem ="0">Action</dropdownList>
</presentation>
</presentationTable>
</resources>
</policyDefinitionResources>

<!--
DXT_34f51d8da07c479bae41dd8db061812f
txt_warning_period
DXT_8ab92f9f21e642dd9c343c1f185c8b4b
-->
55 changes: 16 additions & 39 deletions src/Lithnet.IdleLogoff/PolicyDefinitions/lithnet.idlelogoff.admx
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,47 @@
</definitions>
</supportedOn>
<categories>
<category name="CAT_78275968_599A_4E3F_BAD6_07C70894AF09" displayName="$(string.CAT_78275968_599A_4E3F_BAD6_07C70894AF09)">
<category name="cat_idle_logoff" displayName="$(string.cat_idle_logoff)">
<parentCategory ref="lithnet:CAT_300017F2_090D_4E59_A535_01350C2E0428" />
</category>
</categories>
<policies>
<policy name="POL_978C1C26_0621_4860_A000_61A23A440151" class="Machine" displayName="$(string.POL_978C1C26_0621_4860_A000_61A23A440151)" presentation="$(presentation.POL_978C1C26_0621_4860_A000_61A23A440151)" key="Software\Policies\Lithnet\IdleLogoff" valueName="Enabled">
<parentCategory ref="CAT_78275968_599A_4E3F_BAD6_07C70894AF09" />


<policy name="pol_show_warning_message" class="Both" displayName="$(string.pol_show_warning_message)" presentation="$(presentation.pol_show_warning_message)" key="Software\Policies\Lithnet\IdleLogoff" valueName="WarningEnabled" explainText="$(string.pol_show_warning_message_help)">
<parentCategory ref="cat_idle_logoff" />
<supportedOn ref="TS_SUPPORTED_WindowsXP" />
<elements>
<decimal id="DXT_7E914D9D_203C_40DF_8C49_93B29308A6B2" key="Software\Policies\Lithnet\IdleLogoff" valueName="IdleLimit" minValue="1" />
<decimal id="DXT_34f51d8da07c479bae41dd8db061812f" key="Software\Policies\Lithnet\IdleLogoff" valueName="WarningPeriod" minValue="0" />
<boolean id="DXT_B357DAA7-0013-45D9-94DC-E91206837C29" key="Software\Policies\Lithnet\IdleLogoff" valueName="IgnoreDisplayRequested">
<trueValue>
<decimal value="1" />
</trueValue>
<falseValue>
<decimal value="0" />
</falseValue>
</boolean>
<enum id="DXT_3E1833A6-D761-40B5-8BF9-5C03F320C86B" key="Software\Policies\Lithnet\IdleLogoff" valueName="Action">
<item displayName="$(string.POL_F3930A2B-33F8-4CE6-B6AC-14F188507B77)">
<value>
<decimal value="0" />
</value>
</item>
<item displayName="$(string.POL_D61A5346-B53C-42FB-99FF-6519F18B281C)">
<value>
<decimal value="1" />
</value>
</item>
<item displayName="$(string.POL_582D5654-4165-42D2-BF83-6A182FF67587)">
<value>
<decimal value="2" />
</value>
</item>
</enum>
<decimal id="txt_warning_period" key="Software\Policies\Lithnet\IdleLogoff" valueName="WarningPeriod" minValue="10" />
<text id="txt_warning_message" key="Software\Policies\Lithnet\IdleLogoff" valueName="WarningMessage" required="false"/>
</elements>
</policy>
<policy name="POL_1D519699-D182-4B28-A489-1F7DE9DB6DE5" class="User" displayName="$(string.POL_978C1C26_0621_4860_A000_61A23A440151)" presentation="$(presentation.POL_1D519699-D182-4B28-A489-1F7DE9DB6DE5)" key="Software\Policies\Lithnet\IdleLogoff" valueName="Enabled">
<parentCategory ref="CAT_78275968_599A_4E3F_BAD6_07C70894AF09" />

<policy name="pol_enable_idle_logoff" class="Both" displayName="$(string.pol_enable_idle_logoff)" presentation="$(presentation.pol_enable_idle_logoff)" key="Software\Policies\Lithnet\IdleLogoff" valueName="Enabled">
<parentCategory ref="cat_idle_logoff" />
<supportedOn ref="TS_SUPPORTED_WindowsXP" />
<elements>
<decimal id="DXT_B29D2480-E131-4C23-B4D4-F55CAA13C2FF" key="Software\Policies\Lithnet\IdleLogoff" valueName="IdleLimit" minValue="1" />
<decimal id="DXT_8ab92f9f21e642dd9c343c1f185c8b4b" key="Software\Policies\Lithnet\IdleLogoff" valueName="WarningPeriod" minValue="0" />
<boolean id="DXT_CFF2EAC7-2034-47F9-B3CE-8D10C73FCA81" key="Software\Policies\Lithnet\IdleLogoff" valueName="IgnoreDisplayRequested">
<decimal id="txt_idle_limit" key="Software\Policies\Lithnet\IdleLogoff" valueName="IdleLimit" minValue="1" />
<boolean id="ck_ignore_display_requested" key="Software\Policies\Lithnet\IdleLogoff" valueName="IgnoreDisplayRequested">
<trueValue>
<decimal value="1" />
</trueValue>
<falseValue>
<decimal value="0" />
</falseValue>
</boolean>
<enum id="DXT_6C79F5D5-6DB7-4194-BCB5-7CF6752263EA" key="Software\Policies\Lithnet\IdleLogoff" valueName="Action">
<item displayName="$(string.POL_F3930A2B-33F8-4CE6-B6AC-14F188507B77)">
<enum id="dd_idle_action" key="Software\Policies\Lithnet\IdleLogoff" valueName="Action">
<item displayName="$(string.string_logoff)">
<value>
<decimal value="0" />
</value>
</item>
<item displayName="$(string.POL_D61A5346-B53C-42FB-99FF-6519F18B281C)">
<item displayName="$(string.string_reboot)">
<value>
<decimal value="1" />
</value>
</item>
<item displayName="$(string.POL_582D5654-4165-42D2-BF83-6A182FF67587)">
<item displayName="$(string.string_shutdown)">
<value>
<decimal value="2" />
</value>
Expand Down
5 changes: 3 additions & 2 deletions src/Lithnet.IdleLogoff/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static void EventTimer_Tick(object sender, EventArgs e)
{
Program.expectedIdleActionTime = DateTime.Now.AddMilliseconds(Settings.IdleLimitMilliseconds);
Trace.WriteLine($"Set expected idle action time to: {Program.expectedIdleActionTime}");
if (Settings.WarningPeriod > 0)
if (Settings.WarningEnabled && Settings.WarningPeriod > 0)
{
Program.expectedWarningTime = DateTime.Now.AddMilliseconds(Settings.WarningPeriodMilliseconds);
Trace.WriteLine($"Set expected warning time to: {Program.expectedWarningTime}");
Expand All @@ -154,7 +154,8 @@ private static void EventTimer_Tick(object sender, EventArgs e)
Program.isIdle = true;
}

if (Settings.WarningPeriod > 0
if (Settings.WarningEnabled
&& Settings.WarningPeriod > 0
&& DateTime.Now >= Program.expectedWarningTime
&& DateTime.Now < Program.expectedIdleActionTime)
{
Expand Down
46 changes: 46 additions & 0 deletions src/Lithnet.IdleLogoff/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,52 @@ public static bool Enabled
set => Settings.SaveSetting("Enabled", Convert.ToInt32(value), RegistryValueKind.DWord);
}

public static bool WarningEnabled
{
get
{
object value = null;
bool status = false;

value = Settings.GetPolicyOrSetting("WarningEnabled");
if (value != null)
{
try
{
if ((int)value == 1)
{
status = true;
}
}
catch
{
//unable to cast
}

}
return status;
}
set => Settings.SaveSetting("WarningEnabled", Convert.ToInt32(value), RegistryValueKind.DWord);
}

public static string WarningMessage
{
get
{
string value = Settings.GetPolicyOrSetting("WarningMessage") as string;

if (string.IsNullOrWhiteSpace(value))
{
return "Your session has been idle for too long, and you will be logged out in {0} seconds";
}
else
{
return value;
}
}
set => Settings.SaveSetting("WarningMessage", value, RegistryValueKind.String);
}

public static IdleTimeoutAction Action
{
get
Expand Down
Loading

0 comments on commit 45fde7a

Please sign in to comment.