Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-11-03
8
Medium Priority
?
268 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
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 57

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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 

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 57

Accepted Solution

by:
McKnife earned 2000 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 57

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
Suggested Courses

877 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