home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0066_Network Interface for DELPHI.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  10.5 KB  |  362 lines

  1. (*
  2.    I hope somebody finds the following code useful.
  3. This code has been adapted from ALLSWAG.  It returns the Network
  4. station number, user name and full name.  I have tested it with
  5. Novell Netware 3.12 and WFW.
  6.  
  7.     At least I hope this will save some of you some time.  It took me
  8. some time to figure out exactly how to get it done.  (Now it appears
  9. clearer :))
  10.  
  11. Even if you don't understand the details, you can still use the
  12. functions.  For the sake of those like me, who are new to the
  13. language:  You can copy the code in between the dotted lines and put
  14. it in a file and use it as a unit.
  15. *)
  16.  
  17. unit General;
  18.  
  19. interface
  20. function StationNumber:byte;
  21. Function GetNetUserName : String;
  22. Function GetNetFullName(User_Name : String) : String;
  23.  
  24. implementation
  25. function StationNumber:byte;  { MY logical Station(connection)-Number }
  26. var
  27.  RetVal : Byte;
  28. begin
  29.  asm
  30.    MOV AH, $DC;
  31.    INT 21H
  32.    MOV RetVal, AL;
  33.  end;
  34.  Result := Retval;
  35. end;
  36.  
  37.  
  38. Function GetNetUserName : String;
  39.  
  40. var
  41.   Request : record                     { Request buffer for "Get Conn Info" }
  42.     Len  : Word;                       { Buffer length - 2                  }
  43.     Func : Byte;                       { Subfunction number ( = $16 )       }
  44.     Conn : Byte                        { Connection number to be researched }
  45.   end;
  46.  
  47.   Reply    : record                    { Reply buffer for "Get Conn Info"   }
  48.     Len    : Word;                     { Buffer length - 2                  }
  49.     ID     : Longint;                  { Object ID (hi-lo order)            }
  50.     Obj    : Word;                     { Object type (hi-lo order again)    }
  51.     Name   : array[ 1..48 ] of Byte;   { Object name as ASCII string        }
  52.     Time   : array[ 1.. 7 ] of Byte;   { Y, M, D, Hr, Min, Sec, DOW         }
  53.                                        { Y < 80 is in the next century      }
  54.                                        { DOW = 0 -> 6, Sunday -> Saturday   }
  55.     Filler : Byte                      { Call screws up without this!       }
  56.   end;
  57.  
  58.   W      : Word;
  59.   RetVal : Byte;
  60.  
  61. begin
  62.                                        { "Get Connection Information"       }
  63.   with Request do                      { Initialize request buffer:         }
  64.   begin
  65.     Len := 2;                                    { Buffer length,           }
  66.     Func := $16;                                 { API function,            }
  67.     Conn := StationNumber                    { Returned in previous call!         }
  68.   end;
  69.  
  70.   Reply.Len := SizeOf( Reply ) - 2;    { Initialize reply buffer length     }
  71.  
  72.   asm
  73.    push ds
  74.    push ss
  75.    push es
  76.     MOV AH, $E3;                         { Connection Services API call       }
  77.     LEA SI, Request               { Location of request buffer         }
  78.     PUSH SS
  79.     POP DS
  80.     LEA DI, Reply                { Location of reply buffer           }
  81.     PUSH SS
  82.     POP ES
  83.     INT 21H
  84.     MOV RetVal, AL
  85.     pop ES
  86.     pop SS
  87.     pop DS
  88.   end;
  89.  
  90.   if ( RetVal = 0 )                        { Success code returned in AL   }
  91.        and ( Hi( Reply.Obj ) = 1 )          { Obj of 1 is a user,           }
  92.        and ( Lo( Reply.Obj ) = 0 ) then     {   stored Hi-Lo                }
  93.     with Reply do
  94.     begin
  95.       Move( Name, Result[ 1 ], 48 );           { Convert ASCIIZ to string }
  96.       Result[ 0 ] := #48;
  97.       W := 1;
  98.       while ( Result[ W ] <> #0 )
  99.             and ( W < 48 ) do
  100.         Inc( W );
  101.       Result[ 0 ] := Char( W - 1 )
  102.     end
  103.   else
  104.     Result := ''
  105. end;
  106.  
  107.  
  108. Function GetNetFullName(User_Name : String) : String;
  109. Type
  110.   RequestBuffer = Record
  111.     RequestBufferLength : Word;
  112.     Code                : Byte;
  113.     ObjectType          : Word;
  114.     ObjectNameLength    : Byte;
  115.     ObjectName          : Array[1..48] of char;
  116.     SegmentNumber       : Byte;
  117.     PropertyNameLength  : Byte;
  118.     PropertyName        : Array[1..15] of char;
  119.   end;
  120.  
  121.   ReplyBuffer = Record
  122.     ReplyBufferLength : Word;
  123.     PropertyValue     : Array[1..128] of char;
  124.     MoreSegments      : Byte;
  125.     PropertyFlags     : Byte;
  126.   end;
  127.  
  128. Var
  129.   Request : RequestBuffer;
  130.   Reply   : ReplyBuffer;
  131.   PropertyName : String[15];
  132.   Counter : Byte;
  133.   Temp    : String[128];
  134.  
  135. begin
  136.   PropertyName := 'IDENTIFICATION';
  137.   Request.RequestBufferLength := SizeOf(Request) - 2;
  138.   Request.Code := $3D;
  139.   Request.SegmentNumber := 1;
  140.   Request.ObjectType := $0100;
  141.   Request.ObjectNameLength := SizeOf(Request.ObjectName);
  142.   FillChar(Request.ObjectName, SizeOf(Request.ObjectName), #0);
  143.  
  144.   For Counter := 1 to length(User_Name) do
  145.     Request.ObjectName[Counter] := User_Name[Counter];
  146.  
  147.   Request.PropertyNameLength := SizeOf(Request.PropertyName);
  148.   FillChar(Request.PropertyName, SizeOf(Request.PropertyName), #0);
  149.  
  150.   For Counter := 1 to Length(PropertyName) do
  151.     Request.PropertyName[Counter] := PropertyName[Counter];
  152.   Reply.ReplyBufferLength := SizeOf(Reply) - 2;
  153.  
  154.  asm
  155.   PUSH SS
  156.   PUSH DS
  157.   MOV AH, $E3;
  158.   LEA SI, Request
  159.   PUSH SS
  160.   POP DS
  161.   LEA DI,Reply
  162.   PUSH SS
  163.   POP ES
  164.   INT 21H
  165.   POP DS
  166.   POP SS
  167.  end;
  168.  
  169.   Temp := '';
  170.   Counter := 1;
  171.   While (Reply.PropertyValue[Counter] <> #0) do
  172.   begin
  173.     Temp := Temp + Reply.PropertyValue[Counter];
  174.     inc(Counter);
  175.   end;
  176.   Result := Temp;
  177. end;
  178. end.
  179. -------------Code Ends------------------------
  180.  
  181. Sajan Thomas
  182. Computer and Communication Services Department
  183. Milwaukee School of Engineering
  184. Milwaukee, WI 53202
  185. Tel. (414)-277-7498
  186. (Internet Address: THOMAS@MSOE.EDU)
  187.  
  188. -------------------------------------------------------------------------------
  189.  
  190.    Here is a function to get the login date and time from Netware.
  191. The function returns the result in TDateTime format, which can be
  192. formatted with any of the built-in routines.
  193. e.g.
  194. DateString := FormatDateTime('"I  logged in on" dddd, mmmm d, yyyy, ' +
  195. '"at" hh:mm AM/PM', GetLoginTime(stationnumber)); 
  196.  returns the login date and time for the current user. ( It uses the 
  197. StationNumber function that I posted yesterday).
  198.    You can find out the login date and time for any station, provided 
  199. you _know_ the station number.  The results of the function when 
  200. supplied a non-existant station number is unpredictable!!
  201.    Again, this function has been adapted from material found in the 
  202. ALLSWAG.ZIP file.
  203.  
  204.   Hope this helps someone.
  205.  
  206. Enjoy,
  207. Sajan.
  208.  
  209.  
  210. ----code begins--------------------
  211. Function GetLoginTime(LogicalStationNo: Integer):TDateTime;
  212. Var
  213.   I,X            : Integer;
  214.   RequestBuffer  : Record
  215.                      PacketLength : Integer;
  216.                      FunctionVal  : Byte;
  217.                      ConnectionNo : Byte;
  218.                    end;
  219.   ReplyBuffer    : Record
  220.                      ReturnLength : Integer;
  221.                      UniqueID1    : Packed Array [1..2] of Byte;
  222.                      UniqueID2    : Packed Array [1..2] of Byte;
  223.                      ConnType     : Packed Array [1..2] of Byte;
  224.                      ObjectName   : Packed Array [1..48] of Byte;
  225.                      LoginTime    : Packed Array [1..8] of Byte;
  226.                    end;
  227.   Month          : String[3];
  228.   Year,
  229.   Day,
  230.   Hour,
  231.   Minute         : String[2];
  232.   retval : byte;
  233.  
  234. Begin
  235.   With RequestBuffer Do begin
  236.     PacketLength := 2;
  237.     FunctionVal := 22;  { 22 = Get Station Info }
  238.     ConnectionNo := LogicalStationNo;
  239.   end;
  240.   ReplyBuffer.ReturnLength := 62;
  241.   asm
  242.     push ds
  243.     push ss
  244.     mov ah, $e3;
  245.     lea SI, RequestBuffer
  246.     push ss
  247.     pop ds
  248.     lea di, ReplyBuffer
  249.     push ss
  250.     pop es
  251.     int 21h
  252.     mov retval, al
  253.     pop ss
  254.     pop ds
  255.   end;
  256.   if RetVal = 0 then
  257.    begin
  258.     With ReplyBuffer Do
  259.      begin
  260.        Str(LoginTime[1]:2,Year);
  261.        Str(LoginTime[2], Month);
  262.        Str(LoginTime[3]:2,Day);
  263.        Str(LoginTime[4]:2,Hour);
  264.        Str(LoginTime[5]:2,Minute);
  265.        if Day[1] = ' ' then Day[1] := '0';
  266.        if Hour[1] = ' ' then Hour[1] := '0';
  267.        if Minute[1] = ' ' then Minute[1] := '0';
  268.        Result := StrToDateTime(Month+'/'+Day+'/'+Year+' ' + Hour + ':' + Minute);
  269.     end { With };
  270.    end;
  271. End;
  272. ----------code ends-----------------
  273.  
  274. Sajan Thomas
  275. Computer and Communication Services Department
  276. Milwaukee School of Engineering
  277. Milwaukee, WI 53202
  278. Tel. (414)-277-7498
  279. (Internet Address: THOMAS@MSOE.EDU)
  280.  
  281. unit Netapi;
  282.  
  283. interface
  284. type
  285.  TFileServerName = array [0..48] of char;
  286.  TNodeAddress = record
  287.     nodeHi : longint;
  288.     nodeLo : Integer;
  289.     end;
  290.  
  291.  
  292. Function GetConnectionNumber:Longint;
  293. Function GetConnectionID(fileServerName:TFileServerName; var connectionID:integer):Integer;
  294. Function GetDefaultConnectionID:Integer;
  295. Procedure GetFileServerName(connID:integer; var fileservername:TFileServerName);
  296. Function GetInternetAddress(connectionNumber : longint; var networkNumber: longint;
  297.          var physicalNodeAddress:TNodeAddress; var socketNumber: integer):Integer;
  298. Function IntSwap(unswappedInteger : integer):Integer;
  299. Function LongSwap(unswappedLong : longint):Longint;
  300. Function GetNetworkNumber : String;
  301. Function GetNodeAddress : String;
  302. {Call example: FileServerName(GetDefaultConnectionID) }
  303. Function FileServerName(connID : integer) : String;
  304.  
  305.  
  306. implementation
  307. Uses SysUtils;
  308. Function GetInternetAddress; external 'NWNETAPI';
  309. Function GetConnectionNumber; external 'NWNETAPI';
  310. Function GetConnectionID; external 'NWNETAPI';
  311. Function GetDefaultConnectionID; external 'NWNETAPI';
  312. Procedure GetFileServerName; external 'NWNETAPI';
  313. Function IntSwap; external 'NWNETAPI';
  314. Function LongSwap; external 'NWNETAPI';
  315.  
  316. Function GetNetworkNumber : String;
  317.  var
  318.   networkno : longint;
  319.   nodeaddr : TNodeAddress;
  320.   socketno : integer;
  321. Begin
  322.  GetInternetAddress(GetConnectionNumber,networkno, nodeaddr, socketno);
  323.  Result := IntToHex(LongSwap(networkno), 1);
  324. End;
  325.  
  326.  
  327.  
  328. Function GetNodeAddress : String;
  329.  var
  330.   networkno : longint;
  331.   nodeaddr : TNodeAddress;
  332.   socketno : integer;
  333. Begin
  334.  GetInternetAddress(GetConnectionNumber,networkno, nodeaddr, socketno);
  335.  Result := IntToHex(longswap(nodeaddr.nodehi), 1) +
  336.            IntToHex(lo(nodeaddr.nodelo), 1) +
  337.            IntToHex(hi(nodeaddr.nodelo), 1);
  338. End;
  339.  
  340. Function FileServerName(connID : integer) : String;
  341. Var
  342.  FSName : TFileServerName;
  343. Begin
  344.  FillChar(FSName, 48, ' ');  {need to initialize it}
  345.  GetFileServerName(connID, FSName);
  346.  Result := StrPas(FSName);
  347. End;
  348.  
  349. end.
  350. ---------- code ends---------------
  351.  
  352. Enjoy,
  353. Sajan.
  354.  
  355. Sajan Thomas
  356. Computer and Communication Services Department
  357. Milwaukee School of Engineering
  358. Milwaukee, WI 53202
  359. Tel. (414)-277-7498
  360. (Internet Address: THOMAS@MSOE.EDU)
  361.  
  362.