1

I want to create a program that "locks" my work station as soon as I leave or move away from my computer. And automatically starts again as soon as the user login.

I'm using Opencv to track my movement and its working.

now I want to know how can I automatically start a function again as soon as the user login using c++

I'm using

LockWorkStation();

to lock my system

I have a C# implementation for it which I got from
Programmatically Determine a Duration of a Locked Workstation?

const int SessionUnlockParam = 0x8;

if (m.WParam.ToInt32() == SessionUnlockParam)
{OnSessionUnlock(); // Do something when unlocked
}

void OnSessionUnlock()
{
 // Do something......  
}

can someone tell me how to to do this in C++ and which libraries to use

or

How can I access Event IDs in C++ such as: " Event_ID = 4801 - The workstation was unlocked".

for windows 8

Muhammad Bin Ali
  • 205
  • 2
  • 13
  • Technically, asking for libraries is off-topic for stack overflow. However, I see no reason why the rest of your question wouldn't be on topic. I don't know the answer, though. –  Sep 10 '19 at 17:01
  • I don't believe this is actually a duplicate of checking if the workstation is locked. Muhammad wants to be notified of session changes, the linked solution would require polling. – Alex Broadwin Sep 10 '19 at 17:09
  • I have tried This https://stackoverflow.com/questions/29326685/c-check-if-computer-is-locked But It doesn't work on visual studio 2015 – Muhammad Bin Ali Sep 10 '19 at 18:27

1 Answers1

2

You can register a window to receive events for session changes using WTSRegisterSessionNotification.

Then listen for WM_WTSSESSION_CHANGE with a wParam value of WTS_SESSION_UNLOCK.

Alex Broadwin
  • 1,288
  • 11
  • 23