Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Группа в XP [D6, WinXP]


akim2 ©   (2003-12-15 17:32:00) 

Добрый всем!

Подскажите пож, как можно прочитать Workgroup в кот я сейчас работаю? В 2000 нашел а в XP не могу. Может кто знает?


Игорь Шевченко   (2003-12-15 22:08:00) [1]

unit main;

interface

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

type
TfMain = class(TForm)
Label1: TLabel;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
end;

var
fMain: TfMain;

implementation
uses
HSNetApi;

{$R *.dfm}

procedure TfMain.FormCreate(Sender: TObject);
var
S : PWideChar;
rc : DWORD;
begin
rc := NetpGetDomainName(@S);
if rc = NOERROR then begin
Edit1.Text := WideCharToString(S);
NetApiBufferFree(S);
end else
Edit1.Text := Format("Error %d", [rc]);
end;

end.


unit HSNetApi;

interface
uses
Windows;

function NetApiBufferFree (lpBuffer : Pointer) : Integer; stdcall;
function NetpGetDomainName (lpBuffer : Pointer) : Integer; stdcall;
function NetpGetComputerName (lpBuffer : Pointer) : Integer; stdcall;

implementation
uses
SysUtils;

{ NETAPI32.DLL functions }
type
TNetApiBufferFree =
function (lpBuffer : Pointer) : Integer; stdcall;
TNetpGetDomainName =
function (lpBuffer : Pointer) : Integer; stdcall;
TNetpGetComputerName =
function (lpBuffer : Pointer) : Integer; stdcall;

const
netapidllname = "netapi32.dll";

var
NetApiDllHandle: THandle;
_NetApiBufferFree : TNetApiBufferFree;
_NetpGetDomainName : TNetpGetDomainName;
_NetpGetComputerName : TNetpGetComputerName;

function InitNetApi : Boolean;
begin
if NetApiDllHandle = 0 then
if Win32Platform = VER_PLATFORM_WIN32_NT then begin
NetApiDllHandle := LoadLibrary(NetApidllname);
if NetApiDllHandle <> 0 then begin
@_NetApiBufferFree := GetProcAddress(NetApiDllHandle,
"NetApiBufferFree");
@_NetpGetDomainName := GetProcAddress(NetApiDllHandle,
"NetpGetDomainName");
@_NetpGetComputerName := GetProcAddress(NetApiDllHandle,
"NetpGetComputerName");
end;
end;
Result := (NetApiDllHandle <> 0);
end;

function NetApiNotImplemented : Integer;
begin
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
Result := ERROR_PROC_NOT_FOUND;
end;

function NetApiBufferFree (lpBuffer : Pointer) : Integer; stdcall;
begin
if InitNetApi and Assigned(_NetApiBufferFree) then
Result := _NetApiBufferFree(lpBuffer)
else
Result := NetApiNotImplemented;
end;

function NetpGetDomainName (lpBuffer : Pointer) : Integer; stdcall;
begin
if InitNetApi and Assigned(_NetpGetDomainName) then
Result := _NetpGetDomainName(lpBuffer)
else
Result := NetApiNotImplemented;
end;

function NetpGetComputerName (lpBuffer : Pointer) : Integer; stdcall;
begin
if InitNetApi and Assigned(_NetpGetComputerName) then
Result := _NetpGetComputerName(lpBuffer)
else
Result := NetApiNotImplemented;
end;

initialization
finalization
if NetApiDllHandle <> 0 then
FreeLibrary(NetApiDllHandle);
end.


Наверх

Титульная страница Поиск, карта сайта Написать письмо