Forum > Windows

How to get notified, when user unlocks workstation


I would like my program to be notified, when a user unlocks windows (eg. after windows+l or automatic LockWorkStation by screensaver og gpo).
I have tried the "" from
I have changed "Execution Level" to "asInvoker"
The codes is like:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, windows, LMessages; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Button3: TButton;    Memo1: TMemo;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure Button3Click(Sender: TObject);    procedure WndProc(var TheMessage: TLMessage); override;  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } function WTSRegisterSessionNotification(hWnd: HWND; dwFlags: DWORD): BOOL; stdcall external 'Wtsapi32.dll';function WTSUnRegisterSessionNotification(hWnd: HWND): BOOL; stdcall external 'Wtsapi32.dll';function LockWorkStation: BOOL; stdcall external 'User32.dll'; procedure TForm1.Button1Click(Sender: TObject);begin  SetLastError(0);  if WTSRegisterSessionNotification(WindowHandle,0) then Memo1.Lines.Add('REGISTRED');  if GetLastError<>0 then Memo1.Lines.Add('ERROR: '+IntToStr(GetLastError));end; procedure TForm1.Button2Click(Sender: TObject);begin  SetLastError(0);  if WTSUnRegisterSessionNotification(WindowHandle) then Memo1.Lines.Add('UNREGISTRED');  if GetLastError<>0 then Memo1.Lines.Add('ERROR: '+IntToStr(GetLastError));end; procedure TForm1.Button3Click(Sender: TObject);begin  LockWorkStation;end; procedure TForm1.WndProc(var TheMessage: TLMessage);begin  if TheMessage.msg=WM_WTSSESSION_CHANGE then  begin    Memo1.Lines.Add('- WM_WTSSESSION_CHANGE -');  end;  inherited WndProc(TheMessage);end; end. 
If I try to register (by pressing Button1), GetLastError returns 5 - and when the workstation is locked/unlocked, I never get to  line 65: Memo1.Lines.Add('- WM_WTSSESSION_CHANGE -');
The result is the same, if i run the program with elevated rigths.

Any suggestions?



Thank You - it solved my problem (and it works when compiled for 64bit as well as when compiled for 32bit)


[0] Message Index

Go to full version