From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Windows Log in/Log off Triggers

Solved!
Go to solution

Hi,

 

How can I detect when a user has logged ON/OFF or Unlocked/Locked the screen in Windows?

I would like to trigger an event in my code to restart or end a subroutine whenever the user is present only.

 

Regards,

Jega

0 Kudos
Message 1 of 8
(2,734 Views)

You can poll who the user is with this:

au.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 8
(2,693 Views)
Solution
Accepted by RavensFan

.NET to the rescue!

 

Register for a .NET event:

Register for SessionSwitch.PNG

You can delete the structure and the timing VI and replace it with your real code... just don't unregister til you're ready to exit.

 

This is an example of a callback VI... all it does is a popup telling you what kind of session switch happened:

 

SessionSwitch callback.PNG

Example code attached.  Just replace the popup window with something that sends a signal to your program as a user event, queue, whatever that a session change has occurred. 

Download All
0 Kudos
Message 3 of 8
(2,679 Views)

Kyle97330,

 

Can you save it under LabVIEW 2013 or earlier? I am on LabVIEW 2013 SP1.

 

Regards,

Jega

0 Kudos
Message 4 of 8
(2,676 Views)

Attached.  Sorry it took a while, I went home right after posting that yesterday.

Download All
0 Kudos
Message 5 of 8
(2,654 Views)

Kyle97330,

 

This is awesome!... Exactly what I needed. Thank you.

Quick question, do we need the Event Common Data, Control Ref and User Parameter variables in the Callback VI?

 

Capture.PNG

 

 

 

0 Kudos
Message 6 of 8
(2,643 Views)
Solution
Accepted by topic author Sable

The callback VI has to have a connection pane that matches exactly what the event registration expects, so they need to stay there and connected to the pane, even if unused.  When using the .NET "Register event callback" node, you right-click it and choose "Create callback VI" and it creates one for you that has the correct pane.

 

(Side note:  Since it seems to work, you can go ahead and click "Mark as solution" so future forum searchers find it easier...)

0 Kudos
Message 7 of 8
(2,625 Views)

Thank you so much Kyle97330.

0 Kudos
Message 8 of 8
(2,606 Views)