Solved

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

Posted on 2016-11-03
8
56 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 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 54

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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 54

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 54

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Resolve DNS query failed errors for Exchange
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

809 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