我需要根据当前登录用户的位置限制应用程序的特定功能.由于我必须在Delphi中实现这个逻辑,所以我不希望过度使用完整的活动目录/ LDAP查询.
我的想法是利用DsGetDcName,并使用DOMAIN_CONTROLLER_INFO结构中返回的GUID并将其与硬编码常量进行比较.似乎原因是域GUID只会在重新创建域时发生变化,因此这将提供我想要的功能,而且开销有限.我唯一关心的是我在MSDN上找不到任何证明我的假设的文档.
type
EAccessDenied = Exception;
EInvalidOwner = Exception;
EInsufficientBuffer = Exception;
ELibraryNotFound = Exception;
NET_API_STATUS = Integer;
TDomainControllerInfoA = record
DomainControllerName: LPSTR;
DomainControllerAddress: LPSTR;
DomainControllerAddressType: ULONG;
DomainGuid: TGUID;
DomainName: LPSTR;
DnsForestName: LPSTR;
Flags: ULONG;
DcSiteName: LPSTR;
ClientSiteName: LPSTR;
end;
PDomainControllerInfoA = ^TDomainControllerInfoA;
const
NERR_Success = 0;
procedure NetCheck(ErrCode: NET_API_STATUS);
begin
if ErrCode <> NERR_Success then
begin
case ErrCode of
ERROR_ACCESS_DENIED:
raise EAccessDenied.Create('Access is Denied');
ERROR_INVALID_OWNER:
raise EInvalidOwner.Create('Cannot assign the owner of this object.');
ERROR_INSUFFICIENT_BUFFER:
raise EInsufficientBuffer.Create('Buffer passed was …Run Code Online (Sandbox Code Playgroud)