windows - Run a batch file when I lock/unlock my computer

06
2014-04
  • intA

    Is there a way I can run a batch file upon locking my computer, and then run another batch file when I unlock it? (Windows 8.1)

    Thank you!

  • Answers
  • davidbaumann

    I am sorry I can't give you english screenshots.
    Just create a task in planned tasks.
    At the "trigger" tab, you can select "At lock" and "At unlock".

  • SoFLy

    As user294496 pointed out, one of the fastest ways to do this would be to set a "Scheduled Task" up to execute your batch files at lock/unlock.

    Another option would be to take a look here and see if this little GUI tool that somebody wrote for something similar might be a better option for you if you don't want to do this using scheduled tasks. If you are interested in writing some C#, I'll bet it wouldn't be too difficult to write a utility similar to this.


  • Related Question

    How to extract part of a string, in Windows batch file?
  • Ken

    If I have a variable in a batch (cmd) file that looks like "Abc_123", and I want to end up with a variable that has just "123", is there any built-in way to do this?

    I'm not terribly picky about the method, or performance, as long as it's built in to a typical Windows (Vista/2008) system.


  • Related Answers
  • John T

    Use the substring syntax:

    C:\Users\John>set string=Abc_123
    
    C:\Users\John>echo %string%
    Abc_123
    
    C:\Users\John>echo %string:~4,3%
    123
    
  • Wayne Johnston

    If you find that the batch language isn't powerful enough to do what you want - and it likely won't take you too long to get to that point - you can use the Windows PowerShell. This isn't installed by default on all versions of Windows, but you can download it free of charge.

    If you don't like the PowerShell language, there's Perl. You'll have to install that on all systems though. There are others too.