0

Initial situation

I'm working with multiple workstations on a domain where I'm not allowed to change screensaver or power saving options which is very common nowadays. I often have to switch between PCs and they get locked after 10 idle minutes. Horrible.

Currently I'm using caffeine to prevent screensaver and system lock. But this leads to the problem that my PCs are connected to the network 24/7 all the time. Even at night when I manually have locked all my workstations with Win+L.

What I want to achieve

My idea is to automate these four tasks with AutoIt or AutoHotKey and trash all 3rd party software

  1. Disable a specific network interface once when system is locked and time is between 8 pm and 6 am
  2. Re-enable a specific network interface once when system is unlocked
  3. Ping a specific IP when system is not locked (this is for keeping a firewall open)
  4. Simulate a keypress once every minute so the system won't lock the screen or activate the screensaver

What I have tried so far

Since SU isn't about Give me the code, I started googling around for a way to determine a safe way if Windows is locked. It turns out that using WinExist("A") isn't reliable enough and I'm stuck.

Second, I know I can simulate a keypress in a loop but I don't know which key I should use, that doesn't accidentally opens or executes something.

9
  • Second, I know I can simulate a keypress in a loop but I don't know which key I should use. Try emulating ScrollLock. I can't think of any Windows software using it nowadays. – Vladimir Tsuverkalov Sep 19 '13 at 9:39
  • 1
    refer to this answer for scripting your adapter on/off. superuser.com/a/526272/179299 credits to @nixda – Lorenzo Von Matterhorn Sep 19 '13 at 11:46
  • What do you mean by "Connected to the network"? Also, why is that a bad thing? Even when your machine doesn't use caffeine, it's still connected to the network when the machine is locked and/or a screensaver is running. – MDMoore313 Sep 19 '13 at 12:46
  • @MDMoore313 You misunderstood me: Caffeine is not for disabling the network adapter, its just for preventing the screensaver+getting locked. I just want to automatically disable my network adapter while I manually have locked the system – nixda Sep 19 '13 at 12:52
  • I understand, just curious what you wanted to accomplish? Are you unable to schedule tasks? If you can sch. tasks, do you have permissions to disable the network adapter manually? If not, then no automated solution will help :-( – MDMoore313 Sep 19 '13 at 12:53
1

I would use a powershell script to automate this, using a scheduled task to run the script. You could either have

1)A separate script for each event (logon/logoff, lock/unlock) 2)Pass a single script different parameters based on the event (auto.ps1 /unlock, for example)

Personally I like #2, a little more work upfront but easier to manage. You probably want to look in the event logs to correspond the event you want your scheduled task to be triggered on, I don't believe there is an action in sch. task settings for all 4 of those events, though I could be mistaken.

Finally, make sure your machine can run powershell scripts outright or call powershell.exe with the appropriate parameters:

powershell.exe -noprofile -executionpolicy bypass -file C:\autoping.ps1
1
  • 1
    I think this answer is the way to go. At most it would be two scripts. – Lee Harrison Sep 19 '13 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.