diff --git a/src/Lithnet.IdleLogoff/LogoffWarning.Designer.cs b/src/Lithnet.IdleLogoff/LogoffWarning.Designer.cs index a7b93d7..31b4e32 100644 --- a/src/Lithnet.IdleLogoff/LogoffWarning.Designer.cs +++ b/src/Lithnet.IdleLogoff/LogoffWarning.Designer.cs @@ -42,10 +42,11 @@ private void InitializeComponent() this.lbWarning.Size = new System.Drawing.Size(431, 71); this.lbWarning.TabIndex = 0; this.lbWarning.Text = "Your session has been idle for too long, and you will be logged out in {0} second" + - "s. Move the mouse or press any key to cancel"; + "s\r\n"; // // button1 // + this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.button1.Location = new System.Drawing.Point(214, 111); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(104, 34); @@ -82,7 +83,6 @@ private void InitializeComponent() this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Idle session logoff"; this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.LogoffWarning_KeyPress); - this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.LogoffWarning_MouseMove); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); diff --git a/src/Lithnet.IdleLogoff/LogoffWarning.cs b/src/Lithnet.IdleLogoff/LogoffWarning.cs index 1622eca..1edf565 100644 --- a/src/Lithnet.IdleLogoff/LogoffWarning.cs +++ b/src/Lithnet.IdleLogoff/LogoffWarning.cs @@ -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"); diff --git a/src/Lithnet.IdleLogoff/PolicyDefinitions/en-US/lithnet.idlelogoff.adml b/src/Lithnet.IdleLogoff/PolicyDefinitions/en-US/lithnet.idlelogoff.adml index da47c24..cf2989f 100644 --- a/src/Lithnet.IdleLogoff/PolicyDefinitions/en-US/lithnet.idlelogoff.adml +++ b/src/Lithnet.IdleLogoff/PolicyDefinitions/en-US/lithnet.idlelogoff.adml @@ -5,32 +5,37 @@ - IdleLogoff - Log off inactive users - Log off - Reboot - Shutdown + IdleLogoff + Log off inactive users + Show a warning message before logging off + 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. + + Log off + Reboot + Shutdown At least Microsoft Windows At least Microsoft Windows XP - - Idle timeout (minutes) - Show a warning for before logging the user off (seconds before logoff) - Ignore sleep prevention requests from applications such as media playback - Action + + Duration of warning message (seconds) + + + Your session has been idle for too long, and you will be logged out in {0} seconds + - - Idle timeout (minutes) - Show a warning for before logging the user off (seconds before logoff) - Ignore sleep prevention requests from applications such as media playback - Action + + Idle timeout (minutes) + Ignore sleep prevention requests from applications such as media playback + Action \ No newline at end of file diff --git a/src/Lithnet.IdleLogoff/PolicyDefinitions/lithnet.idlelogoff.admx b/src/Lithnet.IdleLogoff/PolicyDefinitions/lithnet.idlelogoff.admx index c9d1086..b63b7f2 100644 --- a/src/Lithnet.IdleLogoff/PolicyDefinitions/lithnet.idlelogoff.admx +++ b/src/Lithnet.IdleLogoff/PolicyDefinitions/lithnet.idlelogoff.admx @@ -13,51 +13,28 @@ - + - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + + - - - + + @@ -65,18 +42,18 @@ - - + + - + - + diff --git a/src/Lithnet.IdleLogoff/Program.cs b/src/Lithnet.IdleLogoff/Program.cs index 28caacd..63b8793 100644 --- a/src/Lithnet.IdleLogoff/Program.cs +++ b/src/Lithnet.IdleLogoff/Program.cs @@ -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}"); @@ -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) { diff --git a/src/Lithnet.IdleLogoff/Settings.cs b/src/Lithnet.IdleLogoff/Settings.cs index 9c337ff..5642815 100644 --- a/src/Lithnet.IdleLogoff/Settings.cs +++ b/src/Lithnet.IdleLogoff/Settings.cs @@ -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 diff --git a/src/Lithnet.IdleLogoff/frmSettings.Designer.cs b/src/Lithnet.IdleLogoff/frmSettings.Designer.cs index 1c3962b..1c4dcbb 100644 --- a/src/Lithnet.IdleLogoff/frmSettings.Designer.cs +++ b/src/Lithnet.IdleLogoff/frmSettings.Designer.cs @@ -42,6 +42,9 @@ private void InitializeComponent() this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.udWarning = new System.Windows.Forms.NumericUpDown(); + this.ckShowWarning = new System.Windows.Forms.CheckBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtWarningMessage = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.udMinutes)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.udWarning)).BeginInit(); this.SuspendLayout(); @@ -58,7 +61,7 @@ private void InitializeComponent() // // udMinutes // - this.udMinutes.Location = new System.Drawing.Point(229, 53); + this.udMinutes.Location = new System.Drawing.Point(323, 53); this.udMinutes.Maximum = new decimal(new int[] { 35791, 0, @@ -89,7 +92,7 @@ private void InitializeComponent() // // btOK // - this.btOK.Location = new System.Drawing.Point(345, 235); + this.btOK.Location = new System.Drawing.Point(345, 297); this.btOK.Name = "btOK"; this.btOK.Size = new System.Drawing.Size(71, 24); this.btOK.TabIndex = 4; @@ -100,7 +103,7 @@ private void InitializeComponent() // btCancel // this.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btCancel.Location = new System.Drawing.Point(268, 235); + this.btCancel.Location = new System.Drawing.Point(268, 297); this.btCancel.Name = "btCancel"; this.btCancel.Size = new System.Drawing.Size(71, 24); this.btCancel.TabIndex = 3; @@ -111,7 +114,7 @@ private void InitializeComponent() // lbProductName // this.lbProductName.AutoSize = true; - this.lbProductName.Location = new System.Drawing.Point(8, 237); + this.lbProductName.Location = new System.Drawing.Point(8, 299); this.lbProductName.Name = "lbProductName"; this.lbProductName.Size = new System.Drawing.Size(99, 13); this.lbProductName.TabIndex = 4; @@ -119,7 +122,7 @@ private void InitializeComponent() // // lbProductVersion // - this.lbProductVersion.Location = new System.Drawing.Point(8, 250); + this.lbProductVersion.Location = new System.Drawing.Point(8, 312); this.lbProductVersion.Name = "lbProductVersion"; this.lbProductVersion.Size = new System.Drawing.Size(119, 13); this.lbProductVersion.TabIndex = 5; @@ -130,7 +133,7 @@ private void InitializeComponent() this.lbGPControlled.Dock = System.Windows.Forms.DockStyle.Top; this.lbGPControlled.Location = new System.Drawing.Point(0, 0); this.lbGPControlled.Name = "lbGPControlled"; - this.lbGPControlled.Size = new System.Drawing.Size(427, 15); + this.lbGPControlled.Size = new System.Drawing.Size(434, 15); this.lbGPControlled.TabIndex = 6; this.lbGPControlled.Text = "Some settings are currently configured by group policy and cannot be modified"; this.lbGPControlled.Visible = false; @@ -145,9 +148,9 @@ private void InitializeComponent() // // ckIgnoreDisplayRequested // - this.ckIgnoreDisplayRequested.Location = new System.Drawing.Point(39, 165); + this.ckIgnoreDisplayRequested.Location = new System.Drawing.Point(38, 232); this.ckIgnoreDisplayRequested.Name = "ckIgnoreDisplayRequested"; - this.ckIgnoreDisplayRequested.Size = new System.Drawing.Size(315, 34); + this.ckIgnoreDisplayRequested.Size = new System.Drawing.Size(378, 34); this.ckIgnoreDisplayRequested.TabIndex = 8; this.ckIgnoreDisplayRequested.Text = "Ignore sleep prevention requests from applications such as media playback"; this.ckIgnoreDisplayRequested.UseVisualStyleBackColor = true; @@ -156,7 +159,7 @@ private void InitializeComponent() // this.cbAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbAction.FormattingEnabled = true; - this.cbAction.Location = new System.Drawing.Point(156, 83); + this.cbAction.Location = new System.Drawing.Point(250, 76); this.cbAction.Name = "cbAction"; this.cbAction.Size = new System.Drawing.Size(166, 21); this.cbAction.TabIndex = 10; @@ -164,7 +167,7 @@ private void InitializeComponent() // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(35, 84); + this.label2.Location = new System.Drawing.Point(37, 79); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(40, 13); this.label2.TabIndex = 11; @@ -172,15 +175,15 @@ private void InitializeComponent() // // label3 // - this.label3.Location = new System.Drawing.Point(35, 110); + this.label3.Location = new System.Drawing.Point(37, 144); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(188, 32); + this.label3.Size = new System.Drawing.Size(282, 20); this.label3.TabIndex = 13; - this.label3.Text = "Show a warning before idle action is taken (seconds)"; + this.label3.Text = "Duration of warning message (seconds)"; // // udWarning // - this.udWarning.Location = new System.Drawing.Point(229, 110); + this.udWarning.Location = new System.Drawing.Point(323, 142); this.udWarning.Maximum = new decimal(new int[] { 35791, 0, @@ -195,13 +198,43 @@ private void InitializeComponent() 0, 0}); // + // ckShowWarning + // + this.ckShowWarning.AutoSize = true; + this.ckShowWarning.Location = new System.Drawing.Point(38, 122); + this.ckShowWarning.Name = "ckShowWarning"; + this.ckShowWarning.Size = new System.Drawing.Size(251, 17); + this.ckShowWarning.TabIndex = 14; + this.ckShowWarning.Text = "Show a warning message before idle action"; + this.ckShowWarning.UseVisualStyleBackColor = true; + this.ckShowWarning.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(37, 164); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(139, 13); + this.label4.TabIndex = 15; + this.label4.Text = "Custom warning message"; + // + // txtWarningMessage + // + this.txtWarningMessage.Location = new System.Drawing.Point(40, 182); + this.txtWarningMessage.Name = "txtWarningMessage"; + this.txtWarningMessage.Size = new System.Drawing.Size(378, 22); + this.txtWarningMessage.TabIndex = 16; + // // FrmSettings // this.AcceptButton = this.btOK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btCancel; - this.ClientSize = new System.Drawing.Size(427, 271); + this.ClientSize = new System.Drawing.Size(434, 334); + this.Controls.Add(this.txtWarningMessage); + this.Controls.Add(this.label4); + this.Controls.Add(this.ckShowWarning); this.Controls.Add(this.label3); this.Controls.Add(this.udWarning); this.Controls.Add(this.label2); @@ -246,5 +279,8 @@ private void InitializeComponent() private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.NumericUpDown udWarning; + private System.Windows.Forms.CheckBox ckShowWarning; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txtWarningMessage; } } \ No newline at end of file diff --git a/src/Lithnet.IdleLogoff/frmSettings.cs b/src/Lithnet.IdleLogoff/frmSettings.cs index 59bf77c..1b683c4 100644 --- a/src/Lithnet.IdleLogoff/frmSettings.cs +++ b/src/Lithnet.IdleLogoff/frmSettings.cs @@ -17,7 +17,7 @@ private void frmSettings_Load(object sender, EventArgs e) private void RefreshUI() { - this.lbProductName.Text = "Lithnet.idlelogoff"; + this.lbProductName.Text = "Lithnet Idle Logoff"; this.lbProductVersion.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(3); this.ckEnableIdleLogoff.Checked = Settings.Enabled; @@ -45,12 +45,18 @@ private void RefreshUI() this.udMinutes.Value = 60; } - this.udWarning.Value = Settings.WarningPeriod; - this.udMinutes.Enabled = !Settings.IsSettingFromPolicy(nameof(Settings.IdleLimit)); + + this.ckShowWarning.Checked = Settings.WarningEnabled; + this.ckShowWarning.Enabled = !Settings.IsSettingFromPolicy(nameof(Settings.WarningEnabled)); + this.udWarning.Enabled = !Settings.IsSettingFromPolicy(nameof(Settings.WarningPeriod)); + this.udWarning.Value = Settings.WarningPeriod; + + this.txtWarningMessage.Enabled = !Settings.IsSettingFromPolicy(nameof(Settings.WarningMessage)); + this.txtWarningMessage.Text = Settings.WarningMessage; - if (!this.udMinutes.Enabled | !this.ckEnableIdleLogoff.Enabled | !this.ckIgnoreDisplayRequested.Enabled | !this.udWarning.Enabled) + if (!this.udMinutes.Enabled | !this.ckEnableIdleLogoff.Enabled | !this.ckIgnoreDisplayRequested.Enabled | !this.udWarning.Enabled | !this.txtWarningMessage.Enabled | !this.ckShowWarning.Enabled) { this.lbGPControlled.Visible = true; } @@ -67,7 +73,7 @@ private void btOK_Click(object sender, EventArgs e) if (this.udMinutes.Enabled) { - Settings.IdleLimit = (int) this.udMinutes.Value; + Settings.IdleLimit = (int)this.udMinutes.Value; } if (this.ckIgnoreDisplayRequested.Enabled) @@ -75,9 +81,19 @@ private void btOK_Click(object sender, EventArgs e) Settings.IgnoreDisplayRequested = this.ckIgnoreDisplayRequested.Checked; } + if (this.ckShowWarning.Enabled) + { + Settings.WarningEnabled = this.ckShowWarning.Checked; + } + + if (this.txtWarningMessage.Enabled) + { + Settings.WarningMessage = this.txtWarningMessage.Text; + } + if (this.udWarning.Enabled) { - Settings.WarningPeriod = (int) this.udWarning.Value; + Settings.WarningPeriod = (int)this.udWarning.Value; } if (this.cbAction.Enabled) @@ -124,5 +140,10 @@ private void btCancel_Click(object sender, EventArgs e) { Environment.Exit(0); } + + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + + } } }