まずこれらのネットワーク管理APIと列挙を定義します。
uses Windows; type NET_API_STATUS = DWORD; {$EXTERNALSYM NET_API_STATUS} _NETSETUP_JOIN_STATUS = (NetSetupUnknownStatus = 0, // The status is unknown. NetSetupUnjoined, // The computer is not joined. NetSetupWorkgroupName, // The computer is joined to a workgroup. NetSetupDomainName); // The computer is joined to a domain. {$EXTERNALSYM _NETSETUP_JOIN_STATUS} NETSETUP_JOIN_STATUS = _NETSETUP_JOIN_STATUS; {$EXTERNALSYM NETSETUP_JOIN_STATUS} PNETSETUP_JOIN_STATUS = ^NETSETUP_JOIN_STATUS; {$EXTERNALSYM PNETSETUP_JOIN_STATUS} TNetsetupJoinStatus = NETSETUP_JOIN_STATUS; const NERR_Success = 0; {$EXTERNALSYM NERR_Success} function NetGetJoinInformation(lpServer: PWideChar; var lpNameBuffer: PWideChar; BufferType: PNETSETUP_JOIN_STATUS): NET_API_STATUS; stdcall; external 'netapi32.dll' Name 'NetGetJoinInformation'; {$EXTERNALSYM NetGetJoinInformation} function NetApiBufferFree(Buffer: Pointer): NET_API_STATUS; stdcall; external 'netapi32.dll' Name 'NetApiBufferFree'; {$EXTERNALSYM NetApiBufferFree}
あとはこれを呼び出すだけです。
function GetNetworkJoinInformation(var NetworkName: String; var Status: TNetsetupJoinStatus): Boolean; var Buffer: PWideChar; begin if NetGetJoinInformation(nil,Buffer,@Status) <> NERR_Success then begin Result := False; Exit; end; NetworkName := Buffer; NetApiBufferFree(Buffer); Result := True; end;
0 件のコメント:
コメントを投稿