StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
randomConstant  
#1 Posted : Saturday, February 26, 2022 6:41:49 AM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 115
Pakistan

Thanks: 32 times
Was thanked: 10 time(s) in 9 post(s)
Hi all

As the title suggests, I would like to know how S+ behaves when Windows is in sleep mode or locked(the time when you wake it up by pressing any key and it asks for password)

It is more of a confirmation post actually because I know programs do keep their processes alive when Windows is asleep(or at least they dont kill the program entirely)

Here's my use case, I do some things before turning Windows off, such as unmounting any VeraCrypt containers and logging some information to files. I have a shortcut set(in S+) to turn off Windows which does those things and then turns off Windows.

Sometimes I fall asleep and Windows goes to sleep mode for 7 to 10 hours, leaving VeraCrypt containers mounted and vulnerable.
I would like to set a timer which fires every 15 minutes and turns off Windows after 3 hours of inactivity(by monitoring mouse pointer location changes?) and that way I can turn Windows off properly(after unmounting VeraCrypt containers using S+ that is)

But I'm not sure how much 'alive' S+ really is when Windows is locked in sleep mode, is it able to fire timers? can it run programs? such as writing to files and running VeraCrypt command lines..

I could test it with trial and error but honestly I can't be sure until someone(aka Rob Laugh ) confirms it.
Any clarification and ideas regarding the best 'monitoring' practices when Windows is locked in sleep mode are much appreciated.

Thanks
Rob  
#2 Posted : Saturday, February 26, 2022 9:08:11 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,185
United States
Location: Tampa, FL

Thanks: 25 times
Was thanked: 364 time(s) in 317 post(s)
I've never tried any of these things before, but it looks like it can be accomplished via WinAPI calls.

https://www.codeproject.com/Articles/49798/Wake-the-PC-from-standby-or-hibernation

Note some of the comments in the post regarding power config settings.
thanks 1 user thanked Rob for this useful post.
randomConstant on 2/27/2022(UTC)
randomConstant  
#3 Posted : Sunday, February 27, 2022 6:23:51 AM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 115
Pakistan

Thanks: 32 times
Was thanked: 10 time(s) in 9 post(s)
Thanks Rob

It looks a bit too complicated for me right now but nice to know an option exists Laugh
Rob  
#4 Posted : Sunday, February 27, 2022 3:37:21 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,185
United States
Location: Tampa, FL

Thanks: 25 times
Was thanked: 364 time(s) in 317 post(s)
But yeah, if you want to just disable sleep in Windows, you can make a timer in S+ to look at the mouse location or call GetLastInputInfo to see when the last input happened.

You could then have S+ do the stuff and put Windows to sleep via SetSuspendState or shutdown.exe.

Also, SetThreadExecutionState tells windows that a process must be running and prevents sleep and/or display from turning off, for what it's worth.
thanks 1 user thanked Rob for this useful post.
randomConstant on 2/28/2022(UTC)
randomConstant  
#5 Posted : Monday, February 28, 2022 9:15:25 AM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 115
Pakistan

Thanks: 32 times
Was thanked: 10 time(s) in 9 post(s)
Informative stuff, I'll implement some of it for sure.

Thanks Rob
johnwang  
#6 Posted : Thursday, March 10, 2022 4:58:23 PM(UTC)
johnwang

Rank: Newbie

Reputation:

Groups: Approved
Joined: 4/2/2020(UTC)
Posts: 9
United States

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
What I do is hook a task scheduler task to the windows screen saver event. There is an onsleep event, but that isn't guaranteed to fire off the task before the computer sleeps.

The screen saver event is not normally logged, so you'll have to go into the Group Policy Editor under Local Computer Policy -> Computer Configuration -> Windows Settings -> Security Settings -> Advanced Audit Policy Configuration -> System Audit Policies -> Logon/Logoff -> Audit Other Logon/Logoff Events. Set that to log Success and Fail.

In Task Scheduler, set the task to begin On an Event. Log: Security, Source: Microsoft Windows security auditing, Event ID: 4802

After that, add any scripts/programs you want to run when the screensaver runs, then as the last action, run a program to set the computer to standby.


Rob  
#7 Posted : Thursday, March 10, 2022 5:25:42 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,185
United States
Location: Tampa, FL

Thanks: 25 times
Was thanked: 364 time(s) in 317 post(s)
You can also create a simple WinForms and handle session ending events broadcast by Windows.
Code:
// Windows message query end session
public const int WM_QUERYENDSESSION = 17;

// Windows message end session
public const int WM_ENDSESSION = 22;

protected override void WndProc(ref Message m)
{
	switch (m.Msg)
	{
		case WM_QUERYENDSESSION:
			// Windows is letting all apps know that the user is requesting 
			// to end the session
			// Do stuff here
			break;
		case WM_ENDSESSION:
			// Windows is ending the session
			// Do stuff here
			break;
	}
	
	base.WndProc(ref m);
}

I will add to the list to create events in S+ so you can respond to these, as S+ does receive these messages.
randomConstant  
#8 Posted : Friday, March 11, 2022 4:37:22 AM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 115
Pakistan

Thanks: 32 times
Was thanked: 10 time(s) in 9 post(s)
Thanks Laugh
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.