A fortune cookie slip

Get a life.  And then write about it. What'd you last do on the project? What'd you last do on the project? Dude, you are *so* clueless.  I have to tell you all about your cluelessness. Get a life.  And then write about it. Get a life.  And then write about it. Get a life.  And then write about it. I've got to get out of here.  Can you send me somewhere else? I feel compelled to read more, but all there is old stuff. Diaryland is da bomb Current | Archives | Contact Me
Related Links | My Personal Journal | Diaryland


�Delphi code to see if a Windows 2000/XP workstation is locked�
2003-10-20, 16:00:00
:


Ever wanted to check if a workstation is locked in Delphi? So did I, that's why I wrote this.

The following code will check to see if a Windows 2000/XP Pro workstation is locked. I haven't tested it under Windows NT or any other OSes. If you use it, I don't imply any warranties of any kind and you assume all responsibilities.

Caveat: I don't know what this does under fast user switching under XP. Personally, for the environment I write code for and the uses this is intended for, I don't care. If you test it and have input about that, I'd be glad to post some information about that.

Be sure to add the units Windows and Variants to your Uses listing.


function WorkstationLocked: boolean;
var
  hd:         HDESK;
  dwLN:       dword;
  pszIN:      array [0..255] of char;
  s:          string;
begin
  hd := OpenInputDesktop(0, False, 0);

  if hd = null then
  begin
    WorkstationLocked := False;
    Exit;
  end;

  dwLN := 0;

  if not GetUserObjectInformation(hd, UOI_NAME, @pszIN, 256, dwLN) then
  begin
    WorkstationLocked := True;
    Exit;
  end;

  CloseDesktop(hd);

  s := AnsiLowerCase(Trim(Copy(pszIN, 0, 256)));

  WorkstationLocked := (s = 'winlogon');
end;

Yes, I edited this after the fact. Don't you hate when you look at your code not more than six hours later and go, "why didn't I see that before?"

Both work, this one is just a bit more brief. Now if only I can remember to incorporate this change tomorrow at work...



2013-03-01

Suckage

2007-01-09

Want to connect to MSN with PHP?

2005-04-11

AtoZed Software's Indy installer *sucks*

2005-01-10

Another thing I don't like about Altiris

2004-10-25

One of the (many) joys of having your own server


Search this site: