Jump to content

Run script every time unlock screen?


Recommended Posts

Hi. I have a windows 10 pro , core i5 tablet. I want a script to run every time I see lock screen, or every time screen goes on, whatever is easier..

I searched didn't find anything similar..

Every time I press the power button, screen goes off. If screen stay of for more than 5 minutes , pc/tablet go in sleep mode. Anyway every time I press power button again, screen goes on regardless if it was in sleep mode or not, and show lock screen.

How can I make it that a script run automatically every time screen goes on?

Thanks,

 

Link to comment
Share on other sites

There are a ton of options for task outside of just that though.   i believe the startup folder is only when you first create a user session and not for subsequent locks and unlocks.   but there aredefinitely ways to create tasks on unlock actions for all users (requires admin settings to save)

Triggers:

On connection of user profile

On workstation unlock 

 

those are the ones you should look into.  Google them to see if you need both triggers, or just the workstation unlock trigger.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

11 hours ago, jdelaney said:

Check out all the options in scheduled tasks.   easiest way to do it.

Whatever I tried didn't work.. It works if I log out, or restart, but don't work if I just press the button of the tablet and screen goes of, press it again and screen goes on.. I spend hours trying everything probably..

Link to comment
Share on other sites

10 hours ago, ViciousXUSMC said:

While the screen is still locked normal means of execution will not launch a script.

But on login you can put a script in the startup folder or set a scheduled tasks to run on startup.

I need to run the script/app every time screen turn on by pressing the button. When screen turn off, it doesn't always go to sleep, or log off. Probably this happens after some time. If I press the button sooner than that, will the script work? I haven't made it..

Link to comment
Share on other sites

9 hours ago, jdelaney said:

There are a ton of options for task outside of just that though.   i believe the startup folder is only when you first create a user session and not for subsequent locks and unlocks.   but there aredefinitely ways to create tasks on unlock actions for all users (requires admin settings to save)

Triggers:

On connection of user profile

On workstation unlock 

 

those are the ones you should look into.  Google them to see if you need both triggers, or just the workstation unlock trigger.

Neither worked.

I replied late, because I wanted to try more everything.

Link to comment
Share on other sites

You must know that script can continue to run if the workstation is locked.  Since pressing the start button of your laptop doesn't even do a workstation lock, I am tempted to say that a script should continue to run after.  Why don't you try running a script that will simply write to a file every second and check it the script continue after pressing the start button to close the laptop and turning on the laptop on the same way after a few seconds.  If it does continue, you would have a solution path there...

Link to comment
Share on other sites

39 minutes ago, Nine said:

You must know that script can continue to run if the workstation is locked.  Since pressing the start button of your laptop doesn't even do a workstation lock, I am tempted to say that a script should continue to run after.  Why don't you try running a script that will simply write to a file every second and check it the script continue after pressing the start button to close the laptop and turning on the laptop on the same way after a few seconds.  If it does continue, you would have a solution path there...

Actually this was something I thought and succeed. I created this script which turn screen off (I use an icon which run the script to turn screen off instead of pressing the power button), then added a sleep(6000) command to script, and I found out that execution of the script was paused, and continued when I press the button to turn screen on..

The beep(500,1000) sounds after I turn screen on, (even if I turn screen on 5 hours later for example), so script works OK, 99% of the time. Some times I hear the beep 6 seconds after screen turn off.. 

This way I do what I ask, but there is a disadvantage: I don't know why, but I have battery drain this way.. 

If I manually do this: Create one script to turn screen off and do whatever else i want next, and script exit, then create another script which i manually run after i turn screen on, there is not battery drain..

So i was searching actually for an alternative method of doing this:

Here is the script if it helps:

#include< AutoItConstants.au3>
#RequireAdmin

;*** This turns monitor off
RunWait("C:\sosimple\shortcuts\nicmd\nircmd.exe monitor off")


;This disconnect internet
RunWait(@ComSpec & " /c netsh interface set interface name=Wi-Fi admin=disabled", "", @SW_HIDE)

Sleep(6000)
Beep(500,1000)
;exit

;This connect internet again
 RunWait(@ComSpec & " /c netsh interface set interface name=Wi-Fi admin=enabled", "", @SW_HIDE)

 

Link to comment
Share on other sites

Link to comment
Share on other sites

On 4/11/2019 at 11:52 PM, jdelaney said:

There are a ton of options for task outside of just that though.   i believe the startup folder is only when you first create a user session and not for subsequent locks and unlocks.   but there aredefinitely ways to create tasks on unlock actions for all users (requires admin settings to save)

Triggers:

On connection of user profile

On workstation unlock 

 

those are the ones you should look into.  Google them to see if you need both triggers, or just the workstation unlock trigger.

Thanks all for helping. Previously I said that , this wasn't working, but I was wrong... By modifying my script to 2 scripts, 1st one with a command to lock screen and using on workstation unlock trigger to run 2nd script it does work.

Thanks all again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...