Board index » delphi » Accessing Netware Usernames

Accessing Netware Usernames

Quote
Kirk J. Stulen wrote:

> I am trying to get the username of the person currently running my
> programs on a Netware Network.  Before, with Paradox 4.5 (DOS), I used
> the following statement to set the private directory to the users home
> directory;

> setprivdir "f:\\home\\" + substr( username(), 1, 8 )

> I am using Delphi Developer v2.0 and have been unable to find any
> reference to a function like username().

> Any help would be appreciated.  If possible could you email a response
> to the address below.

> --
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Kirk J. Stulen
> Computer Analyst
> CCEER-ISD
> Louisiana State University

> Email: k...@www.leeric.lsu.edu
> WWW: http://www.leeric.lsu.edu
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

16 bit

 function GetNetUserName : STring;
 var
    netuser : array[0..255] of char;
    rc : Integer;
    len : Integer;
 begin

    FillChar(netuser, sizeof(netuser), #00);
    len := sizeof(netuser) -1;
    rc := WNetGetUser(netuser, len);
    if (rc = 0) then
       result := strpas(netuser)
    else
       result := '';
end;

32 bit

The WNetGetUser function retrieves the current default user name or the
user name used to establish a network connection.

DWORD WNetGetUser(

    LPTSTR  lpszLocalName,      // address of local name to get user
name for
    LPTSTR  lpszUserName,       // address of buffer for user name
    LPDWORD  lpcchBuffer        // address of buffer size variable
   );  
Parameters

lpszLocalName

Points to a null-terminated string that specifies either the name of the
local device to return the user name for or the name of a network that
the user has made a connection to.
If this parameter is NULL, Windows returns the name of the current user
for the process.
If this parameter is a network name and the user is connected to that
resource using different names, the network provider may not be able to
resolve which user name to return. In this case, the provider may make
an arbitrary choice from the possible user names.

lpszUserName

Points to a buffer that receives the null-terminated user name.

lpcchBuffer

Points to a variable that specifies the size, in characters, of the
buffer pointed to by lpszUserName. If the call fails because the buffer
is not big enough, this variable contains the required buffer size.

Return Value

If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is an error code. To get
extended error information, call GetLastError. GetLastError may return
one of the following error codes:

Value   Meaning
ERROR_NOT_CONNECTED     The device specified by lpszLocalName is not a
redirected device or a connected network name.
ERROR_MORE_DATA The buffer is too small.
ERROR_NO_NETWORK        No network is present.
ERROR_EXTENDED_ERROR    A network-specific error occurred. To get a
description of the error, use the WNetGetLastError function.
ERROR_NO_NET_OR_BAD_PATH        None of the providers recognized this
local name as having a connection. However, the network is not available
for at least one provider to whom the connection may belong.
The function returns error codes for compatibility with Windows version
3.1. For compatibility with the Win32 API, the function also sets the
error code value returned by GetLastError.

See Also

WNetGetConnection, WNetGetLastError

 

Re:Accessing Netware Usernames


I am trying to get the username of the person currently running my
programs on a Netware Network.  Before, with Paradox 4.5 (DOS), I used
the following statement to set the private directory to the users home
directory;

setprivdir "f:\\home\\" + substr( username(), 1, 8 )

I am using Delphi Developer v2.0 and have been unable to find any
reference to a function like username().

Any help would be appreciated.  If possible could you email a response
to the address below.

--
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Kirk J. Stulen
Computer Analyst
CCEER-ISD
Louisiana State University

Email: k...@www.leeric.lsu.edu
WWW: http://www.leeric.lsu.edu
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Re:Accessing Netware Usernames


Quote
In article <320949C2.2...@pacbell.net>, Adeniji <aden...@pacbell.net> wrote:
>The WNetGetUser function retrieves the current default user name or the
>user name used to establish a network connection.

>DWORD WNetGetUser(

>    LPTSTR  lpszLocalName,      // address of local name to get user
>name for
>    LPTSTR  lpszUserName,       // address of buffer for user name
>    LPDWORD  lpcchBuffer        // address of buffer size variable
>   );  
>Parameters

Great, I'm this far.

I get problems loading the dll.

He can not find the functions. Can you give me a sample?

I'm getting quite desperate.

R.E. den Braasem (aka The Graphical Gnome)

Senior Software Engineer

Re:Accessing Netware Usernames


In article <Dvv24u....@ktibv.nl>, r...@ktibv.nl (The Graphical Gnome) wrote:

Quote
>In article <320949C2.2...@pacbell.net>, Adeniji <aden...@pacbell.net> wrote:
>>The WNetGetUser function retrieves the current default user name or the
>>user name used to establish a network connection.

>>DWORD WNetGetUser(

>>    LPTSTR  lpszLocalName,      // address of local name to get user
>>name for
>>    LPTSTR  lpszUserName,       // address of buffer for user name
>>    LPDWORD  lpcchBuffer        // address of buffer size variable
>>   );  
>>Parameters

>Great, I'm this far.

>I get problems loading the dll.

>He can not find the functions. Can you give me a sample?

>I'm getting quite desperate.

>R.E. den Braasem (aka The Graphical Gnome)

>Senior Software Engineer

Ignore, Problem Solved. Novell loads more DLL's then the one selected.

Happy Hacking The Graphical Gnome

----------------------------------------------
| Rob den Braasem    | Voice :-31-79-3531520 |
|                    | Fax   :-31-79-3513561 |
|                    | Mail  : r...@ktibv.nl  |
|                    |-----------------------+---------------------+
| KTI bv             | "I die when it's time for me to die.        |
| P.O. Box 86        | So let me live  my life the way I want to." |
| 2700 AB Zoetermeer |                                             |
| The Netherlands    |   Jimi Hendrix                              |
-------------------------------------------------------------------+

Re:Accessing Netware Usernames


"Kirk J. Stulen" <k...@www.leeric.lsu.edu> wrote:

Quote
>I am trying to get the username of the person currently running my
>programs on a Netware Network.  Before, with Paradox 4.5 (DOS), I used
>the following statement to set the private directory to the users home
>directory;

>setprivdir "f:\\home\\" + substr( username(), 1, 8 )

>I am using Delphi Developer v2.0 and have been unable to find any
>reference to a function like username().

>Any help would be appreciated.  If possible could you email a response
>to the address below.

>--
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>Kirk J. Stulen
>Computer Analyst
>CCEER-ISD
>Louisiana State University

>Email: k...@www.leeric.lsu.edu
>WWW: http://www.leeric.lsu.edu
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1.Using Registry
function user_name:string;
var reg:tregistry;
begin
    reg:=tregistry.create;
    result:='';
    try
        reg.rootkey:=HKey_Local_Machine;
        if reg.openkey('network\logon',false) then begin;
            result:=reg.readstring('username');
        end;
    finally;
        reg.free;
    end;
end;
2. Using GetUserName() Win32 API
3. DbiGetNetUserName() BDE API function.

Re:Accessing Netware Usernames


You can try this code.  I've been using it on a Netware LAN for some time
now with no problems.  It depends on having the NWCALLS.DLL library already
on the users machine; if users have a Netware connection, then they should
already have that DLL.
good luck.
--------------------
unit GetLogin;

{This unit is a wrapper for several external functions in the NWCALLS.DLL}
{Adapted by Ray Buck from code written by Gregory Trubetskoy}
{The unit contains a function that returns the Netware User ID}
{and one that returns the user's full name.}

interface
 uses
  SysUtils, Messages, Dialogs;
function GetUserLogin: string;
function GetUserFullName( SomeUser: string): string;

implementation
  type
    NWTimeStamp = record
      Year:      byte;
      Month:     byte;
      Day:       byte;
      Hour:      byte;
      Minute:    byte;
      Second:    byte;
      DayOfWeek: byte;
    end;

  {Netware API's - require NWCALLS.DLL}
  function NWGetDefaultConnectionID(var Connection: word): word;
           far; external 'NWCALLS';

  function NWGetConnectionNumber(Connection: word; var ConnectionNumber:
word): word;
           far; external 'NWCALLS';

  function NWGetConnectionInformation(Connection: word;
                                      ConnectionNumber: word;
                                      ObjectName: pchar;
                                      var ObjectType: word;
                                      var ObjectID: word;
                                      var LoginTime: NWTimeStamp):word;
           far; external 'NWCALLS';

  function NWReadPropertyValue(Connection:       word;
                               ObjectName:       pChar;
                               ObjectType:       word;
                               PropertyName:     pChar;
                               DataSetIndex:     byte;
                               DataBuffer:       pChar;
                               var More:             byte;
                               var Flags:            byte): word;
           far; external 'NWCALLS';
  { end of Netware API stuff }

function GetUserLogin: string;
var
  ConnectionID: word;
  ConnectionNumber: word;
  RC: word;
  Name: array[0..50] of Char;
  ObjectType: word;
  ObjectID: word;
  LoginTime: NWTimeStamp;
begin
  RC := NWGetDefaultConnectionID(ConnectionID);
  RC := NWGetConnectionNumber(ConnectionID, ConnectionNumber);
  RC := NWGetConnectionInformation( ConnectionID,
                                    ConnectionNumber,
                                    Name,
                                    ObjectType,
                                    ObjectID,
                                    LoginTime);

  Result := StrPas(Name);
end;

function GetUserFullName( SomeUser: string): string;
{The real user name is a 'property' called 'IDENTIFICATON'.
You have to call NWReadPropertyValue passing it
(among other things) your ConnectionID, the name of the object
(same as the login of the user who's full name you need)
and the name property you want to retrieve, in this case
'IDENTIFICATION' (which translated from Novellish to
English means 'Full Name').}

var
  ConnectionID: word;
  RC: word;
  Name: array[0..50] of Char;
  ObjectType: word;
  PropName: array[0..14] of Char;
  DataSetIndex: byte;
  FullName: array[0..127] of Char;
  More: byte;
  Flags: byte;
begin
  RC := NWGetDefaultConnectionID(ConnectionID);
  ObjectType := 256; {user}
  StrPCopy(PropName, 'IDENTIFICATION');
  DataSetIndex := 1;
  StrPCopy(Name, SomeUser);
  RC := NWReadPropertyValue( ConnectionID,
                               Name,
                               ObjectType,
                               PropName,
                               DataSetIndex,
                               FullName,
                               More,
                               Flags);
  if RC = 35324 then
    MessageDlg('No user ' + SomeUser + ' exists on this server!',
                mtError, [mbOK], 0);
  Result := StrPas(FullName);
end;

end.

Kirk J. Stulen <k...@www.leeric.lsu.edu> wrote in article
<3208934B.5...@www.leeric.lsu.edu>...

Quote
> I am trying to get the username of the person currently running my
> programs on a Netware Network.  Before, with Paradox 4.5 (DOS), I used
> the following statement to set the private directory to the users home
> directory;

> setprivdir "f:\\home\\" + substr( username(), 1, 8 )

> I am using Delphi Developer v2.0 and have been unable to find any
> reference to a function like username().

> Any help would be appreciated.  If possible could you email a response
> to the address below.

> --

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++
Quote
> Kirk J. Stulen
> Computer Analyst
> CCEER-ISD
> Louisiana State University

> Email: k...@www.leeric.lsu.edu
> WWW: http://www.leeric.lsu.edu

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++
Quote

Other Threads