두가지 방법이 있습니다
[1]. Delphi/Novell Libraries
You will need to have the Delphi/Novell Libraries (these are available
from Novell)
The following code is just sat inside an onclick event for a button,
it uses the Netware API's from Client32 to perform a NWDSWhoAmI which
returns the name of the connected Novell user.
Steve Conner
steve@ashursts.com
Procedure TForm1.Button1Click(Sender: TObject);
Var
cCode: NWDSCCODE;
lpNull: NPtr;
NDSContext: NWDSContextHandle;
nContext: Array[0..MAX_DN_CHARS] Of NStr;
NWUserName: Array[0..200] Of Char;
Begin
lpNull := Nil;
cCode := NWCallsInit(lpNull,lpNull);
If (cCode < 0) Then
Begin
ShowMessage('Netware Initialisation Failed');
Exit;
End;
NDSContext := NWDSCreateContext;
If NDSContext = ERR_CONTEXT_CREATION Then
Begin
ShowMessage('Failed To Set Current Context');
Exit;
End;
cCode := NWDSGetContext(NDSContext,DCK_NAME_CONTEXT,@nContext);
If (cCode < 0) Then
Begin
ShowMessage('Failed To Get NDS Context');
Exit;
End;
cCode := NWDSWhoAmI(NDSContext,@NWUserName);
If (cCode < 0) Then
Begin
ShowMessage('Failed NDSWhoAmI');
Exit;
End;
ShowMessage(NWUserName);
NWDSFreeContext(NDSContext);
End;
[2]. WNetGetUser()
Take a look at the WNet... functions prototyped in Windows, particularly
WNetGetUser . These are generic network routines and will do the trick
for Netware, NT, etc.
unit netut;
interface
uses WinTypes, SysUtils;
{ getNetUser returns the name of the user who is currently logged
into
the workstation. Will be a null string if the user is not logged
in. }
function getNetUser : string;
implementation
function WNetGetUser (Name: PChar; Var Len: Word): Word; far; External
'User';
function getNetUser : string;
var
{$IFDEF WIN32}
tmpLen : DWord;
{$ELSE}
tmpLen : Word;
{$ENDIF}
Temp: Array [0..255] of Char;
Begin
tmpLen := sizeOf(Temp);
{$IFDEF WIN32}
if getUserName(Temp, tmpLen) then
result := strPas(Temp)
else
result := '';
{$ELSE}
if WNetGetUser (Temp, tmpLen) <> WN_SUCCESS then
result := ''
else
result := strPas(Temp);
{$ENDIF}
end;
end.
카테고리 없음