Einzelnen Beitrag anzeigen

Dezipaitor

Registriert seit: 14. Apr 2003
Ort: Stuttgart
1.701 Beiträge
 
Delphi 7 Professional
 
#14

Re: Tray Icon, Service und Vista

  Alt 15. Mär 2007, 19:53
Da wir in einem Delphiforum sind,
hier der Delphicode zum runterladbaren,obigen C pendant :

Delphi-Quellcode:
program WTSTest;

{$APPTYPE CONSOLE}

uses {win32api_current.zip units bei http://jedi-apilib.sourceforge.net}
  jwaWindows,jwaWTSApi32,SysUtils;


function GetErrorString(err : DWORD) : String;
var s : PCHAR;
begin
  if(FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER or
            FORMAT_MESSAGE_FROM_SYSTEM,
            0,
            err,
            0,
            PCHAR(@s),
            0,
            nil) = 0) then
   begin
     result := 'unkown error';
          exit;
   end;

        result := s;

   LocalFree(HLOCAL(s));

end;

var pInfo : Array of WTS_SESSION_INFO;
    i,count : DWORD;

begin
  writeln('WTSEnumerateSessions (quit with Ctrl+C)');
  writeln;



  while true do
  begin
    if not WTSEnumerateSessions(WTS_CURRENT_SERVER,0,1,PWTS_SESSION_INFO(pInfo),count) then
    begin
      writeln(GetErrorString(GetLastError));
      halt(1);
    end;
    try
      for i := 0 to count -1 do
      begin
        writeln(IntToStr(i)+'.');
        writeln('Session: '+ pInfo[i].pWinStationName);
        writeln('ID: '+IntToStr(pInfo[i].SessionId));
        write('State: ');
        case pInfo[i].State of
          WTSActive : writeln('WTSActive');
          WTSConnected    : writeln('WTSConnected');
     WTSConnectQuery : writeln('WTSConnectQuery');
     WTSShadow    : writeln('WTSShadow');
     WTSDisconnected : writeln('WTSDisconnected');
     WTSIdle    : writeln('WTSIdle');
     WTSListen    : writeln('WTSListen');
     WTSReset    : writeln('WTSReset');
     WTSDown    : writeln('WTSDown');
     WTSInit    : writeln('WTSInit');
   else
        writeln('???');
        end;
      end;
    except
      writeln('Exception caught');
    end;
    writeln;

    WTSFreeMemory(pInfo);

    Sleep(5000);
  end;
end.
Christian
Windows, Tokens, Access Control List, Dateisicherheit, Desktop, Vista Elevation?
Goto: JEDI API LIB & Windows Security Code Library (JWSCL)
  Mit Zitat antworten Zitat