how to prevent automatic log off in windows 7

0

I have a remote machine that runs on Windows 7, it gets logoff by closing all running application and the gets logged in again automatically. It happens every day but not on specific time and without specific task.

enter image description here

After reviewing Event logs as shown above in image, i found few Events with Id 7001 & 7002 with task category 1101 and 1102 respectively.

I use Windows 7. We are suffering from this problem with other 3 machines having same configuration.

To resolve this, I searched on internet and applied the solution regarding customer experience which is mentioned in the link below:

User Logoff Notification for Customer Experience Improvement Program

Can anyone help me to track this issue ?? Am i on right direction to resolve this problem?

EDIT.

After suggestion given by @TwistyImpersonator, i can say following things from detailed Event viewer (Image are attached at the end):

In System events:

following events always occurred AFTER 'Winlog' events:

Service Control Manager-7036-None-The Shell Hardware Detection service entered the stopped state.

And in Application event, following events occurred around the same time frame

Warning-09.11.2017 18:19:29-User-Profile Service-1530-None-Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards.

DETAIL - 1 user registry handles leaked from \Registry\User\S-1-5-21-1277090162-4221482773-868009429-3552: Process 272 (\Device\HarddiskVolume2\Windows\System32\svchost.exe) has opened key \REGISTRY\USER\S-1-5-21-1277090162-4221482773-868009429-3552\Printers\DevModePerUser

Information-09.11.2017 18:19:29-Desktop Window Manager-9009-None-The Desktop Window Manager has exited with code (0x40010004)

System-and-application-Event-log-compare-1

System-and-application-Event-log-compare-2

windows-7
windows
remote-desktop
administrator
event-log
asked on Super User Nov 13, 2017 by Bunty • edited Nov 14, 2017 by Bunty

1 Answer

0

Before judging this answer please know that it is work in progress. The comments got too much and were not really dedicated on answerring the question but instead find the cause of the problem.

I cannot currently get hold of a copy of win7 to check how below code is working on win7, i'll do that next week, or you just tell me what you experience...

---- answer draft ----

Altough the best solution for your problem is to find the cause, i am going to answer the questions title:

"how to prevent automatic logoff in windows 7"

To capture and prevent logoff, the current way i found out was to catch the "formclosing" event of a windows form in C# and check if the CloseReason is CloseReason.WindowsShutDown. This event can then be "denied" by the code.

This is the whole code:

using System;
using System.Windows.Forms;
using System.IO;

namespace BlockLogoffForm
{
    public partial class PreventLogoff : Form
    {
        public PreventLogoff()
        {
            InitializeComponent();
        }

        private void PreventLogoff_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason.Equals(CloseReason.WindowsShutDown))
            {
                File.AppendAllText("c:\\temp\\logofflog.txt","log off prevented at " + DateTime.Now);
                e.Cancel = true;

            }
        }
    }
}

Download the compiled binary here: BlockLogoffForm.exe

At the current design, you would need to start this program and leave it running until the auto logoff actually happens. Further redefinitions could bring up the same running as Tasktray application or similar.

answered on Super User Nov 17, 2017 by Harry • edited Nov 17, 2017 by Harry

User contributions licensed under CC BY-SA 3.0