Solved

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

Posted on 2016-11-03
8
40 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 28

Expert Comment

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

Open in new window

0
 
LVL 33

Expert Comment

by:paulmacd
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 53

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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 53

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 53

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

What to do when Windows Update is not working correctly? What tools can I use to detect the cause of the malfunction problem? What does this numeric error code mean? These and other questions that you have been asking in the past are answered here (…
Resolve DNS query failed errors for Exchange
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…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now