Solved

Workstation "Locked" -mode

Posted on 2004-04-21
15
356 Views
Last Modified: 2010-04-05
Hello!

I need an example of a procedure that triggers everytime when the workstation enters/come off the locked mode.
I know that there is a lot of different methods with dll:s etc. which I've tried but wont get them working.

Need a full example with code how to get this done.

Yours,
Hokki
0
Comment
Question by:hakanfa
  • 8
  • 5
  • 2
15 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10885736
for windows 2000 and newer you can use WinlogonNotification packages
I have an implementation here: http://files.delphi-si.com/WinLogonPackage.zip
to register for an event simply call (in wlgnImport.pas - also an example of the receiving part):
RegisterNotification(WLX_OnLock, WM_USERCHANGED_WLGN, Handle);
0
 

Author Comment

by:hakanfa
ID: 10890271
Hmm, well not sure of how to use it.. Anyway, how about Win NT 4.0?
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 500 total points
ID: 10898124

   Here is the function which detects if the Workstation is locked:

  function IsWorkstationLocked: Boolean;
  var
    hDesktop: HDESK;
  begin
    Result := False;
    hDesktop := OpenDesktop('default', 0, False, DESKTOP_SWITCHDESKTOP);
    if hDesktop <> 0 then
      begin
        Result := not SwitchDesktop(hDesktop);
        CloseDesktop(hDesktop);
      end;
  end;

  You have to trigger this in Timer(see my example below) :

  procedure TForm1.Timer1Timer(Sender: TObject);
  var
    S : String;
  begin
    S := FormatDateTime('[dd.mm.yyyy hh:nn:ss] ', Now);
    if IsWorkstationLocked then
      S := S + 'Locked'
    else
      S := S + 'Unlocked';
    Memo1.Lines.Add(S);
  end;
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10898195
copy the dll to your apps folder (prefered but you can copy it anywhere but if it's not in the syspath you need to specify the complete path to it)
I mentioned everything else :)
0
 

Author Comment

by:hakanfa
ID: 10898873
well Lee Nover, I'm not so familiar with this so can You please be more specific?
A complete snap of code from the client side would do it..I think it is not to much to
ask for 500 pts?

Hokki
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10898908

  hakanfa did you checked my example - it is 100% working ...
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10899315
sorry .. I've uploaded the new version with an example project

logon package registration requires a system reboot because it's loaded by the winlogon process

run the exe, click "register dll", reboot, run exe, click "register notification" then do some test .. lock/unlock the station
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:hakanfa
ID: 10899362
Hello Ivanov G, Your code is complete and IT WORKS! Simple and great, but I'm ready to increase my points
and split dem between You and Lee Nover if his code works too. But as I said if I can't get it working You will
get Your well earned points! Your code is great simple and with no extra dll:s!
0
 

Author Comment

by:hakanfa
ID: 10899479
Lee Nover, I downloaded the Your pack but it seems to be the same code I downloaded
yesterday is this link correct? http://files.delphi-si.com/WinLogonPackage.zip

 
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10899534
http://files.delphi-si.com/lee/WinLogonPackage.zip

sorry about that :(
it's a crazy day
0
 

Author Comment

by:hakanfa
ID: 10901591
Increase points 900
0
 

Author Comment

by:hakanfa
ID: 10901726
Hello,
First of all I want to thank both of You for great support.
1.Ivanovs example did just what i was looking for. Simple without any
   complex dll:s. GREAT SOLUTION! Grade: A 500 pts

2.LE Novers solution is more complex and works great also. One problem
  though, it doesnt work under Win NT?? (Win 200 and XP = OK). A little bit
  complex with dll:s Grade A 400 pts

I dont know how to increase points (couldnt find any "Increase points" filed) and
therefore I'm asking the administrators to act as I wich.. I hope..

THANK YOU GUYS!
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 10907384
open a new question like 'points for Lee_Nover for Q_20962956' ;)

I needed something more than just locked/unlocked so I implemented a winlogon notification package
and I prefere the more 'advanced' methods ... you learn more ;-)
0
 

Author Comment

by:hakanfa
ID: 10907416
..will see what the administrators can do. I asked them to award you as described
in my last comment..Hope they do as I asked them to do. Will see, if not I'll post a new
question like you described

Hokki
0
 

Author Comment

by:hakanfa
ID: 10908248
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now