Solved

Create a scheduled task that would log off users at a certain time daily

Posted on 2016-11-03
8
113 Views
Last Modified: 2016-11-07
We tried creating a task but it only works if the user is logged into the machine and the screen is not Locked with the screen saver policy.

Is there anyway to force the log off ?

Users are running windows 7 64 bit
0
Comment
Question by:AGenMIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 29

Expert Comment

by:Michael Pfister
ID: 41872223
Try
shutdown /l /f 

Open in new window

0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 41872292
It's possible to set a user's logon hours, and then enforce those hours (including forcing logging off) via GPO.
0
 
LVL 55

Expert Comment

by:McKnife
ID: 41873584
@paulmacd: no, force logoff does not logoff the user. It only disconnects from the resource forcefully - this is often mistaken.

@AGenMis: What we do is, create a scheduled task running as system account. It uses a batch that goes:
del %temp%\DisconSessions.txt
del %temp%\delSessions.txt
qwinsta |findstr Disc >%temp%\DisconSessions.txt
findstr /v services %temp%\DisconSessions.txt>%temp%\delSessions.txt
for /f "tokens=2" %%a in (%temp%\delSessions.txt) do logoff %%a

Open in new window

0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:AGenMIS
ID: 41873979
I created a gpo with the scheduled task as shutdown.exe -l -f and just kept the user as %logonuser% and I see the machine getting the policy but the task is not created.

If I run the task on the local machine it runs and logs off the user even if the screen is locked.

Any ideas here maybe the user needs to be an admin?
0
 
LVL 55

Accepted Solution

by:
McKnife earned 500 total points
ID: 41874013
If you would like to create a task using %logonuser%, that would mean it is a policy targeted to user objects, if I am not mistaken. Did you link the policy to an OU with computer accounts instead?

By the way: we use my suggestion ourselves.
0
 

Author Comment

by:AGenMIS
ID: 41874184
Its a computer side policy linked to a set of computers but the task uses the logged on user account
Capture.PNG
Capture2.PNG
0
 
LVL 55

Expert Comment

by:McKnife
ID: 41874188
I told you, this will not work, as far as I remember (and menanwhile, I tried it - no, it does not). That's due to %logonuser%. We can only use %logonuser% on tasks deployed through user policies. Use my suggestion.
0
 

Author Closing Comment

by:AGenMIS
ID: 41877751
Thanks for your assistance the user side policy did the trick for us
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question