Link to home
Start Free TrialLog in
Avatar of Tulip
Tulip

asked on

NetWkstaUserGetInfo is unknown

How can I use this function ??
I want to use it with Level=1 to retrieve the domain
of a user account. The Username is no problem (WNetGetUser) but what about the domain ??
Or is there another way to get it ??
Avatar of geobul
geobul

Hi,

I think that NetWkstaUserGetInfo is available on NT only. If you are using NT, then the second string in the returned structure have to be the domain name.

Regards,
Geo
Yep, this function is only available under NT. Tulip, does your application only run on NT or do plan to release it also for Win9x (with limited functionality then)?

If you wanna run it on both Windows architectures then you need to dynamically bind the application to the netapi32 library. Is that what you want?

Ciao, Mike
Avatar of Tulip

ASKER

geobul: I know that it should be there
But when I compile my app NetWkstaUserGetInfo can't be found / is unknown. That's my problem. I don't know how to include it into my program!
I use NT only.
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Aaah, Barry, just there with the right source in the right moment :-))

Ciao, Mike
sorry to "push" in again i just happened to have the example in my code db  ;-)
No problem with that. You were faster so... :-)

I hope you don't mind that I have reworked your code so it's a bit more Delphi like and shorter (and so easier to read). I don't want points for this code in this question! Here it goes:

function NT_GetWorkstationInfo(var UserName, LogonDomainName, OtherDomainNames, LogonServer: WideString): Boolean;

type
  _WKSTA_USER_INFO_1 = record
    wUserName: PWideChar;
    wLogonDomainName: PWideChar;
    wOtherDomainNames: PWideChar;
    wLogonServer: PWideChar;
  end;

var
  pWKUI1: ^_WKSTA_USER_INFO_1;
  NetWkstaUserGetInfo: function(ServerName: PWideChar; Level: DWORD; var BufPtr): Integer; stdcall;
  Handle: tHandle;

begin
  Result := False;

  UserName := '';
  LogonDomainName := '';
  OtherDomainNames := '';
  LogonServer := '';

  Handle := LoadLibrary('NETAPI32.DLL');
  if Handle <> 0 then
  try
    @NetWkstaUserGetInfo := GetProcAddress(Handle, 'NetWkstaUserGetInfo');
    if Assigned(NetWkstaUserGetInfo) then
    begin
      if NetWkstaUserGetInfo(nil, 1, pWKUI1) = 0 then
      begin
        UserName := pWKUI1.wUserName;
        LogonDomainName := pWKUI1.wLogonDomainName;
        OtherDomainNames := pWKUI1.wOtherDomainNames;
        LogonServer := pWKUI1.wLogonServer;
        Result := True;
      end;
    end;
  finally
    FreeLibrary(Handle);
  end;
end;

Ciao, Mike
Avatar of Tulip

ASKER

Thanks Barry, that's it.
I didn't know how to call that function.
ok cheers to both of you :-)