Hi
I want to be able to run a script or command when the computer is locked. It needs to detect when the computer is locked. (That's the short version of my question)
(Long version cont.)
Happy for the script to be constantly waiting for a specific window (tried waiting for the computer locked window but that didn't work) or poll the system once a minute (Doesn't have to be the exact second the computer is logged)
Pretty much the script needs to add a line to a text file to record when the computer is locked. I generally lock the computer using ALT+CTRL+DEL then pressing ENTER. This isn't going to change anytime soon, so using the Win+L option isn't going to work for me.
Only trouble I'm having is that I can't figure out how to detect when the PC is locked and have it action anything when the system is in locked state. Would also be great to be able to append the text file when I unlock the computer as well, but I think I know how this can be done if I can get the script to run a command when it is locked.
MAKING AN ALTERNATIVE LOCK SCREEN GUI IS NOT AN OPTION. (thought I might point that out)
Any help to detect when the computer is in locked state would be greatly appreciated.
How to detect when the computer is locked and run command?
Started by
BONER
, Jun 03 2010 02:30 AM
11 replies to this topic
#1
-
Posted 03 June 2010 - 02:30 AM
!^Del::FileAppend %A_Now%`n,Log.txt!^Del is a valid hotkey but Ahk does not block it from the system, so this is one way if you always lock with alt+ctrl+del.
Also a quick check showed the WinGetActiveTitle returned nothng when my computer was locked. Maybe you could setup a loop or SetTimer to check the name of the active window and log when it disapears and when there is one to detect again
#2
-
Posted 03 June 2010 - 03:23 AM
if !DllCall("User32\OpenInputDesktop","int",0*0,"int",0*0,"int",0x0001L*1) msgbox desktop is lockedI should probably kick my own ass for providing this but since i am not giving it all to you and you must still implement it i spose its cryptic enuff to not be easily used by idiots
#3
-
Posted 03 June 2010 - 04:12 AM
Never lose.
WIN or LEARN.
WIN or LEARN.
Thanks.....ummmm...None!
That was perfect. I can't believe it's been that simple this whole time.
Now I just have to play around with it so it will log when I unlock my PC too.
Tank.....I'm not exactly sure what your code is....but I'll have a proper look at it later (at work ATM) though if it does what I think it does then that's perfect too!
That was perfect. I can't believe it's been that simple this whole time.
Now I just have to play around with it so it will log when I unlock my PC too.
Tank.....I'm not exactly sure what your code is....but I'll have a proper look at it later (at work ATM) though if it does what I think it does then that's perfect too!
#4
-
Posted 03 June 2010 - 05:51 AM
The solutions from None and tank detect different things:
None's code detects the action of the user locking the screen (well, they could be just changing their password)
tank's code detects if the screen is locked at the present time
tank's code happened to perform the kind of checking that I wanted, and I'm pleased to say it worked for me. Elsewhere in these forums I saw a suggestion that one could use
So thanks, tank!
None's code detects the action of the user locking the screen (well, they could be just changing their password)
tank's code detects if the screen is locked at the present time
tank's code happened to perform the kind of checking that I wanted, and I'm pleased to say it worked for me. Elsewhere in these forums I saw a suggestion that one could use
if (!WinExist("A"))to detect if the screen is locked, but it turns out that (naturally) that code can't tell the difference between the screen being locked and there simply being no windows at all (or at least none that are active).
So thanks, tank!
#5
-
Posted 26 July 2010 - 11:58 PM
if !DllCall("User32\OpenInputDesktop","int",0*0,"int",0*0,"int",0x0001L*1) msgbox desktop is lockedI should probably kick my own ass for providing this but since i am not giving it all to you and you must still implement it i spose its cryptic enuff to not be easily used by idiots
Wow, that was simple, even for an idiot like me!
#6
-
Posted 17 November 2011 - 03:29 PM
if !DllCall("User32\OpenInputDesktop","int",0*0,"int",0*0,"int",0x0001L*1) msgbox desktop is lockedI should probably kick my own ass for providing this but since i am not giving it all to you and you must still implement it i spose its cryptic enuff to not be easily used by idiots
this is glorious, many thanks to you.
#7
-
Posted 17 November 2011 - 06:09 PM
It's not the solution. It returns 0 even if you press Ctrl+Alt+Del and see the options window.
#8
-
Posted 07 April 2012 - 09:36 PM
the options isnt equal to being locked
you actually have to lock the desktop
you actually have to lock the desktop
#9
-
Posted 07 April 2012 - 09:41 PM
Never lose.
WIN or LEARN.
WIN or LEARN.
How about this?
Also, check here for alternatives: <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?t=5359">viewtopic.php?t=5359</a><!-- l -->
old_locked_state = 0 !^Del::FileAppend, %A_Now% locked`n,autohotkey_log.txt ~#L::FileAppend, %A_Now% locked`n,autohotkey_log.txt check_lock: if !DllCall("User32\OpenInputDesktop","int",0*0,"int",0*0,"int",0x0001L*1) locked_state = 1 else locked_state = 0 if locked_state <> %old_locked_state% { if locked_state <> 1 FileAppend %A_Now% unlocked`n,autohotkey_log.txt old_locked_state := locked_state } return
Also, check here for alternatives: <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?t=5359">viewtopic.php?t=5359</a><!-- l -->
#10
-
Posted 07 April 2012 - 10:23 PM
Dear Tank
one idiot is here im very new to scripting and need to use this command with if statement to shut down the user machines if its not locked but couldn't do it.
how can I get this command to work, how to convert it to a format which can be pushed by GPO or SCCM to the users
#11
-
Posted 25 August 2015 - 05:51 PM
I was fast learner and managed to do it all the thing now is i want to add something to my script so it identefy the machine which executed the script already and do not rerun it, somthing like adding a file, if it exist in the machine exit excuting the script..thanks in advance
#12
-
Posted 25 August 2015 - 09:12 PM