Not a blog about the science or practice of travel through books, but perhaps rather about science, practice and travel through books.

Users forget to logoff and computers get locked. Meeting locked computers at the library in the morning has been, I must admit, a small irritation to me. Why not get rid of the irritation, should be possible to write a small script to logout users automatically, shouldn’t it?

When I first googled this, I was a bit surprised not to find complete answers straight ahead, perhaps I didn’t use the “right” search terms, but nevertheless I thought I should document what I did.  Since I’m not really a sysadmin, I didn’t even know what tools to use initially. I was glad to find Task Scheduler, which provides all kinds of options for scheduling. I went with “Create Basic Task…” and followed the quite straight-forward steps, selecting “Start a program”, then “shutdown.exe” as the program/script with arguments “-f -l” to force logoff (after a little bit of googling I admit :)).

Skjermbilde 2013-07-31 kl. 21.11.37

At this point I tried clicking Run, but nothing happened…

Skjermbilde 2013-07-31 kl. 21.05.37

Under the History pane, I was told that “Task Scheduler successfully completed task ‘\autologoff’ , instance ‘[…]’, action ‘[…]’ with return code 1”, which means it failed (the phrasing “successfully completed task” is silly in that matter). Return code 0 means success. From googling I came across a really weird solution for a related problem (seems to have been a bug in Task Scheduler that has later been fixed). Well, I tried using “-f -r” to reboot instead and to my surprise that worked… Hm…?

I should mention that at this point I was logged in using an impersonal account, not my admin account, and that’s when I looked into the properties of the task and found “When running the task, use the following account” under “General”, filled with my own admin user. Moment of enlightenment; of course that was not going to logoff someone else.  Well, how to run the task as the currently logged in user then? Googling did only add to the confusion.

At this point I turned to GPOs. I created a new scheduled task and to my big surprise the field was now filled with “%LogonDomain%\%LoginUser%” – which is the magic to make it run as the currently logged-in user.

Skjermbilde_2013-07-31_kl._21.36.46

I did a test and it worked – hooray! I’ve learn

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s