Utilizamos cookies propias y de terceros. [Más información sobre las cookies].
Política de cookies
Proyecto AjpdSoft

· Inicio
· Buscar
· Contactar
· Cookies
· Descargas
· Foros
· Historia
· Nosotros
· Temas
· Top 10
· Trucos
· Tutoriales
· Wiki
Obtener grupo de trabajo / Dominio de un PC - Delphi
Lenguaje de programación Borland Delphi


Este código obtiene el grupo de trabajo/dominio de un PC:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function obtenerGrupoTrabajo : AnsiString;
type
 WKSTA_INFO_100 = record
   wki100_platform_id: Integer;
   wki100_computername: PWideChar;
   wki100_langroup: PWideChar;
   wki100_ver_major: Integer;
   wki100_ver_minor: Integer;
 end;

 WKSTA_USER_INFO_1 = record
   wkui1_username: PChar;
   wkui1_logon_domain: PChar;
   wkui1_logon_server: PChar;
   wkui1_oth_domains: PChar;
 end;
type
 //Win9X ANSI prototypes from RADMIN32.DLL and RLOCAL32.DLL

 TWin95_NetUserGetInfo = function(ServerName, UserName: PChar; Level: DWORD; var
   BfrPtr: Pointer): Integer;
 stdcall;
 TWin95_NetApiBufferFree = function(BufPtr: Pointer): Integer;
 stdcall;
 TWin95_NetWkstaUserGetInfo = function(Reserved: PChar; Level: Integer; var
   BufPtr: Pointer): Integer;
 stdcall;

 //WinNT UNICODE equivalents from NETAPI32.DLL

 TWinNT_NetWkstaGetInfo = function(ServerName: PWideChar; level: Integer; var
   BufPtr: Pointer): Integer;
 stdcall;
 TWinNT_NetApiBufferFree = function(BufPtr: Pointer): Integer;
 stdcall;

 function IsWinNT: Boolean;
 var
   VersionInfo: TOSVersionInfo;
 begin
   VersionInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
   Result := GetVersionEx(VersionInfo);
   if Result then
     Result := VersionInfo.dwPlatformID = VER_PLATFORM_WIN32_NT;
 end;
var

 Win95_NetUserGetInfo: TWin95_NetUserGetInfo;
 Win95_NetWkstaUserGetInfo: TWin95_NetWkstaUserGetInfo;
 Win95_NetApiBufferFree: TWin95_NetApiBufferFree;

 WinNT_NetWkstaGetInfo: TWinNT_NetWkstaGetInfo;
 WinNT_NetApiBufferFree: TWinNT_NetApiBufferFree;

 WSNT: ^WKSTA_INFO_100;
 WS95: ^WKSTA_USER_INFO_1;

 EC: DWORD;
 hNETAPI: THandle;
begin
 try

   Result := '';

   if IsWinNT then
   begin
     hNETAPI := LoadLibrary('NETAPI32.DLL');
     if hNETAPI <> 0 then
     begin @WinNT_NetWkstaGetInfo := GetProcAddress(hNETAPI, 'NetWkstaGetInfo');
         @WinNT_NetApiBufferFree  := GetProcAddress(hNETAPI, 'NetApiBufferFree');

       EC := WinNT_NetWkstaGetInfo(nil, 100, Pointer(WSNT));
       if EC = 0 then
       begin
         Result := WideCharToString(WSNT^.wki100_langroup);
         WinNT_NetApiBufferFree(Pointer(WSNT));
       end;
     end;
   end
   else
   begin
     hNETAPI := LoadLibrary('RADMIN32.DLL');
     if hNETAPI <> 0 then
     begin @Win95_NetApiBufferFree := GetProcAddress(hNETAPI, 'NetApiBufferFree');
         @Win95_NetUserGetInfo := GetProcAddress(hNETAPI, 'NetUserGetInfoA');

       EC := Win95_NetWkstaUserGetInfo(nil, 1, Pointer(WS95));
       if EC = 0 then
       begin
         Result := WS95^.wkui1_logon_domain;
         Win95_NetApiBufferFree(Pointer(WS95));
       end;
     end;
   end;

 finally
   if hNETAPI <> 0 then
     FreeLibrary(hNETAPI);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(obtenerGrupoTrabajo);
end;

end.




Publicado el: 2005-05-08

Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A