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: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 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,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 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,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 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: Member

Reputation:

Groups: Approved
Joined: 4/2/2020(UTC)
Posts: 11
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,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 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: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 post(s)
Thanks Laugh
soooulp  
#9 Posted : Saturday, July 30, 2022 2:36:14 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
The form I create to show the icons in this post Popup-an-icons-bar seems to flash randomly when loading, and the form has set DoubleBuffered as true. I find some ways probably solve the flash problem for the form with a transplant background.

But I don't know whether both of them will work to stop the flash of form.

One of them also needs to override this function to receive the message.

Code:
protected override void WndProc(ref Message m)  
       {  
           if (m.Msg == 0x0014) // Disable clear background messages
               return;  
           base.WndProc(ref m);  
       } 



The second is to SetStyle of the form, which shows an Error that form.SetStyle is not a function that I set in the code.

Code:
public Form1()
        {
            InitializeComponent();
            base.SetStyle(
            ControlStyles.OptimizedDoubleBuffer
            | ControlStyles.ResizeRedraw
            | ControlStyles.Selectable
            | ControlStyles.AllPaintingInWmPaint // Background erasing is prohibited
            | ControlStyles.UserPaint
            | ControlStyles.SupportsTransparentBackColor
            | ControlStyles.DoubleBuffer  // double buffering
            ,true);
        }

Edited by user Sunday, July 31, 2022 3:20:35 AM(UTC)  | Reason: Not specified

soooulp  
#10 Posted : Saturday, July 30, 2022 6:36:46 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Is this right to the second SetStyle that refer to avoids-display-flickering?

Turn this:
Code:
tabPageLearn.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.Invoke(tabPageLearn, new object[]
{
    System.Windows.Forms.ControlStyles.UserPaint | 
    System.Windows.Forms.ControlStyles.AllPaintingInWmPaint |
    ystem.Windows.Forms.ControlStyles.DoubleBuffer, true
});


To S+
Code:
form.GetType().GetMethod("SetStyle", host.flags(clr.System.Reflection.BindingFlags.Instance, clr.System.Reflection.BindingFlags.NonPublic))
.Invoke(form, new Object() {
        System.Windows.Forms.ControlStyles.UserPaint, 
        System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, 
        System.Windows.Forms.ControlStyles.DoubleBuffer, true}
);

Edited by user Sunday, July 31, 2022 2:11:51 AM(UTC)  | Reason: Not specified

Rob  
#11 Posted : Sunday, July 31, 2022 11:44:02 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Originally Posted by: soooulp Go to Quoted Post
Is this right to the second SetStyle that refer to avoids-display-flickering?

Turn this:
Code:
tabPageLearn.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.Invoke(tabPageLearn, new object[]
{
    System.Windows.Forms.ControlStyles.UserPaint | 
    System.Windows.Forms.ControlStyles.AllPaintingInWmPaint |
    ystem.Windows.Forms.ControlStyles.DoubleBuffer, true
});


To S+
Code:
form.GetType().GetMethod("SetStyle", host.flags(clr.System.Reflection.BindingFlags.Instance, clr.System.Reflection.BindingFlags.NonPublic))
.Invoke(form, new Object() {
        System.Windows.Forms.ControlStyles.UserPaint, 
        System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, 
        System.Windows.Forms.ControlStyles.DoubleBuffer, true}
);


Try something like this:
Code:
var parms = new List(System.Object);
parms.Add(host.flags(System.Windows.Forms.ControlStyles.UserPaint, 
           System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, 
           System.Windows.Forms.ControlStyles.DoubleBuffer)
);

form.GetType().GetMethod("SetStyle", host.flags(clr.System.Reflection.BindingFlags.Instance, clr.System.Reflection.BindingFlags.NonPublic))
.Invoke(form, parms.ToArray(), true);
soooulp  
#12 Posted : Monday, August 1, 2022 12:37:11 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post


Try something like this:


Ops, It shows an Error, "no overload for method 'Invoke' takes 3 arguments"

UserPostedImage



Rob  
#13 Posted : Monday, August 1, 2022 1:25:23 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Oops:
Code:
var parms = new List(System.Object);
parms.Add(host.flags(System.Windows.Forms.ControlStyles.UserPaint, 
           System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, 
           System.Windows.Forms.ControlStyles.DoubleBuffer)
);
parms.Add(true);

form.GetType().GetMethod("SetStyle", host.flags(clr.System.Reflection.BindingFlags.Instance, clr.System.Reflection.BindingFlags.NonPublic))
.Invoke(form, parms.ToArray());
soooulp  
#14 Posted : Monday, August 1, 2022 5:22:38 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Wow, amazing.
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.