Nazwa u?żytkownika... przez sieć...

0

Mam taki mały problem...:

Jak sprawdzić, jaki użytkownik jest zalogowany na danym komputerze ?
Chodzi mi tu o sieć lokalną i -o ile to ważne- WindowsXP.

Na torrym znalazłem taki komponent -nazwy już nie pamiętam- ale nie działał a podobno pokazywał nazwę zalogowanego na danym kompie użytkownika.

Dzięki z góry Cimak

0

:) pozdrawiam

I Metoda

var buffer:string;
buffSize:DWORD;
begin
buffSize:=128;
SetLength(buffer,BuffSize);
GetUserName(PChar(buffer), buffSize);
ShowMessage(buffer);
end;

II Metoda

uses Registry;
{.........}
procedure TForm1.Button1Click(Sender: TObject);
var Rejestr : TRegistry;
i : string;
begin
Rejestr := TRegistry.Create;
Rejestr.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer',False);
i := Rejestr.ReadString('Logon User Name');
Showmessage(i);
Rejestr.Free;
end; 
0

jas_dream: chodzi o siec lokalna

moze to pomoze:

-------> (sent 50 bytes)
01 F8 00 10 00 01 00 00 00 00 00 00 20 43 4B 41 ............ CKA
41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
41 41 41 41 41 41 41 41 41 41 41 41 41 00 00 21 AAAAAAAAAAAAA..!
00 01 ..
Reply from 172.16.20.30 ( N2A )
<------- (received 247 bytes)
01 F8 84 00 00 00 00 01 00 00 00 00 20 43 4B 41 ............ CKA
41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
41 41 41 41 41 41 41 41 41 41 41 41 41 00 00 21 AAAAAAAAAAAAA..!
00 01 00 00 00 00 00 AD 07 4E 32 41 20 20 20 20 .........N2A
20 20 20 20 20 20 20 20 00 04 00 57 4F 52 4B 47 ...WORKG
52 4F 55 50 20 20 20 20 20 20 00 84 00 4E 32 41 ROUP ...N2A
20 20 20 20 20 20 20 20 20 20 20 20 03 04 00 4E ...N
32 41 20 20 20 20 20 20 20 20 20 20 20 20 20 04 2A .
00 57 4F 52 4B 47 52 4F 55 50 20 20 20 20 20 20 .WORKGROUP
1E 84 00 57 4F 52 4B 47 52 4F 55 50 20 20 20 20 ...WORKGROUP
20 20 1D 04 00 01 02 5F 5F 4D 53 42 52 4F 57 53 .....MSBROWS
45 5F 5F 02 01 84 00 00 0B 6A 1F 8B 48 00 00 00 E
......j..H...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 .......

n2a to nazwa uzytkownika

a moze to: http://www.swissdelphicenter.ch/torry/showcode.php?id=1578

0

a moze to: http://www.swissdelphicenter.ch/torry/showcode.php?id=1578

chyba o to mi chodzi, ale nie wiem, bo nie mam pod reka Delphi...

Jak nie bedzie dzialac to napisze.

Dzieki [browar]
Pozdrawia Cimak [cya]

0

a moze to: http://www.swissdelphicenter.ch/torry/showcode.php?id=1578

chyba o to mi chodzi, ale nie wiem, bo nie mam pod reka Delphi...

Jak nie bedzie dzialac to napisze.

Dzieki [browar]
Pozdrawia Cimak [cya]

ehh niestety to nie dziala ale za to mam cos takiego co na pewno dziala sprawdzilem :

unit2:

unit Unit2;

interface

uses Classes, Windows;

type
TAdapterStatus = record
                 adapter_address: array [0..5] of Char;
                 filler: array [1..4*SizeOf(Char)+19*SizeOf(Word)
                                +3*SizeOf(DWORD)] of Byte;
                 end;
THostInfo = record
            username: PWideChar;
            logon_domain: PWideChar;
            oth_domains: PWideChar;
            logon_server: PWideChar;
            end;{record}

  function IsNetConnect : Boolean;
  function AdapterToString(Adapter: TAdapterStatus): string;
  function GetMacAddresses(const Machine: string;
                           const Addresses: TStrings): Integer;
  function GetNetUser(HostName: WideString): THostInfo;

implementation

uses NB30, SysUtils;

function IsNetConnect : Boolean;
begin
  if GetSystemMetrics(SM_NETWORK) AND $01 = $01
  then Result:= True
  else Result:= False;
end;{function}

function AdapterToString(Adapter: TAdapterStatus): string;
begin
  with Adapter do    Result :=
Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x', [
      Integer(adapter_address[0]), Integer(adapter_address[1]),
      Integer(adapter_address[2]), Integer(adapter_address[3]),
      Integer(adapter_address[4]), Integer(adapter_address[5])]);
end;{function}

function GetMacAddresses(const Machine: string;
                         const Addresses: TStrings): Integer;
const  NCBNAMSZ    = 16;        // absolute length of a net name
       MAX_LANA    = 254;       // lana's in range 0 to MAX_LANA inclusive
       NRC_GOODRET = $00;       // good return
       NCBASTAT    = $33;       // NCB ADAPTER STATUS
       NCBRESET    = $32;       // NCB RESET
       NCBENUM     = $37;       // NCB ENUMERATE LANA NUMBERS
type
PNCB = ^TNCB;
TNCBPostProc = procedure (P: PNCB); stdcall;
TNCB = record
       ncb_command: Byte;
       ncb_retcode: Byte;
       ncb_lsn: Byte;
       ncb_num: Byte;
       ncb_buffer: PChar;
       ncb_length: Word;
       ncb_callname: array [0..NCBNAMSZ - 1] of Char;
       ncb_name: array [0..NCBNAMSZ - 1] of Char;
       ncb_rto: Byte;
       ncb_sto: Byte;
       ncb_post: TNCBPostProc;
       ncb_lana_num: Byte;
       ncb_cmd_cplt: Byte;
       ncb_reserve: array [0..9] of Char;
       ncb_event: THandle;
       end;
PLanaEnum = ^TLanaEnum;
TLanaEnum = record
            length: Byte;
            lana: array [0..MAX_LANA] of Byte;
            end;
ASTAT = record
        adapt: TAdapterStatus;
        namebuf: array [0..29] of TNameBuffer;
        end;
var
NCB: TNCB;
Enum: TLanaEnum;
I: Integer;
Adapter: ASTAT;
MachineName: string;
begin
  Result := -1;
  Addresses.Clear;
  MachineName := UpperCase(Machine);
  if MachineName = ''
  then    MachineName := '*';
  FillChar(NCB, SizeOf(NCB), #0);
  NCB.ncb_command := NCBENUM;
  NCB.ncb_buffer := Pointer(@Enum);
  NCB.ncb_length := SizeOf(Enum);
  if Word(NetBios(@NCB)) = NRC_GOODRET
  then  begin
        Result := Enum.Length;
        for I := 0 to Ord(Enum.Length) - 1
        do begin
             FillChar(NCB, SizeOf(TNCB), #0);
             NCB.ncb_command := NCBRESET;
             NCB.ncb_lana_num := Enum.lana[I];
             if Word(NetBios(@NCB)) = NRC_GOODRET
             then begin
                  FillChar(NCB, SizeOf(TNCB), #0);
                  NCB.ncb_command := NCBASTAT;
                  NCB.ncb_lana_num := Enum.lana[i];
                  StrLCopy(NCB.ncb_callname, PChar(MachineName),NCBNAMSZ);
                  StrPCopy(@NCB.ncb_callname[Length(MachineName)],
                  StringOfChar(' ', NCBNAMSZ - Length(MachineName)));
                  NCB.ncb_buffer := PChar(@Adapter);
                  NCB.ncb_length := SizeOf(Adapter);
                  if Word(NetBios(@NCB)) = NRC_GOODRET
                  then Addresses.Add(AdapterToString(Adapter.adapt));
                  end;
           end;
        end;
end;{function}

function
NetWkstaUserEnum(servername: PWideChar;
                     level : DWord;
                 var bufptr: Pointer;
                 prefmaxlen: DWord;
            var entriesread: PDWord;
           var totalentries: PDWord;
           var resumehandle: PDWord ): LongInt ;
                 stdcall; external 'netapi32.dll' name 'NetWkstaUserEnum';

function GetNetUser(HostName: WideString): THostInfo;
var
Info: Pointer;
ElTotal: PDWord;
ElCount: PDWord;
Resume: PDWord;
Error: LongInt;
begin
  Resume:=0;
           NetWkstaUserEnum(PWideChar(HostName),1, Info,0,
                            ElCount,ElTotal,Resume);
    Error:=NetWkstaUserEnum(PWideChar(HostName),1,Info,256*Integer(ElTotal),
                            ElCount,ElTotal,Resume);
    case    Error    of
    ERROR_ACCESS_DENIED: Result.UserName:= 'ERROR - ACCESS DENIED';
    ERROR_MORE_DATA: Result.UserName:= 'ERROR - MORE DATA';
    ERROR_INVALID_LEVEL: Result.UserName:= 'ERROR - INVALID LEVEL';
    else if Info <> nil
         then Result:=THostInfo(info^)
         else begin
              Result.username:= '???';
              Result.logon_domain:= '???';
              Result.oth_domains:= '???';
              Result.logon_server:= '???';
              end;{if}
    end;{case}
end; {function}

end.

unit1:

var
  HostInfo: THostInfo;
begin
  HostInfo := GetNetUser('127.0.0.1'); //nie dziala z gdy sie wpisze host musi byc ip!
  with HostInfo do
  begin
    Memo1.Lines.Add('user name : ' + username + #13#10 +
      'logon domain : ' + logon_domain);
  end;
end;
0

No nie wiem... to z torrego działa bez żadnych problemów (sieć w szkole, WindowsXP)...
To, co podałeś wywala błąd w tym miejscu:

then Result:=THostInfo(info^)

1 użytkowników online, w tym zalogowanych: 0, gości: 1