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 ??
TulipAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
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
0
LischkeCommented:
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
0
TulipAuthor Commented:
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.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

intheCommented:
hi
sounds like your not calling it right
try this example:


FUNCTION NT_GetWorkstationInfo( var outUserName : ShortString;
                                var outLogonDomainName : ShortString;                                 var outOtherDomainNames : ShortString;                                 var outLogonServer : ShortString ) : Boolean;
Type
  _WKSTA_USER_INFO_1 = Record
    wUserName : pWideChar;
    wLogonDomainName : pWideChar;
    wOtherDomainNames : pWideChar;
    wLogonServer : pWideChar;
  End;
Var
  PtrToInfoStructure : Pointer;
  pWKUI1 : ^_WKSTA_USER_INFO_1;
  NetWkstaUserGetInfo : FUNCTION ( ServerName : LPWSTR; Level : DWORD; Var BufPtr ) : LongInt; stdcall;
  Handle : tHandle;
Begin
  Result:=False;
 
  If (@outUserName<>nil) Then
    outUserName:='';
  If (@outLogonDomainName<>nil) Then
    outLogonDomainName:='';
  If (@outOtherDomainNames<>nil) Then
    outOtherDomainNames:='';
  If (@outLogonServer<>nil) Then
    outLogonServer:='';
 
  Handle := LoadLibrary('NETAPI32.DLL');
  If (Handle<>0) Then Begin
    Try
 
@NetWkstaUserGetInfo:=GetProcAddress(Handle,'NetWkstaUserGetInfo');       If (@NetWkstaUserGetInfo<>nil) Then Begin
        If NetWkstaUserGetInfo( nil, 1, PtrToInfoStructure )=0 Then Begin
          pWKUI1:=PtrToInfoStructure;
          { - UserName - }
          If (Assigned(pWKUI1^.wUserName)) And (@outUserName<>nil) Then             outUserName:=WideCharToString(pWKUI1^.wUserName);
          { - LogonDomainName - }
          If (Assigned(pWKUI1^.wLogonDomainName)) And
(@outLogonDomainName<>nil) Then
 
outLogonDomainName:=WideCharToString(pWKUI1^.wLogonDomainName);
          { - OtherDomainNames - }
          If (Assigned(pWKUI1^.wOtherDomainNames)) And
(@outOtherDomainNames<>nil) Then
 
outOtherDomainNames:=WideCharToString(pWKUI1^.wOtherDomainNames);           { - wLogonServer - }
          If (Assigned(pWKUI1^.wLogonServer)) And (@outLogonServer<>nil) Then
            outLogonServer:=WideCharToString(pWKUI1^.wLogonServer);           Result:=True;
        End;
      End;
    Finally
      FreeLibrary(Handle);
    End;
  End;
End;


Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LischkeCommented:
Aaah, Barry, just there with the right source in the right moment :-))

Ciao, Mike
0
intheCommented:
sorry to "push" in again i just happened to have the example in my code db  ;-)
0
LischkeCommented:
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
0
TulipAuthor Commented:
Thanks Barry, that's it.
I didn't know how to call that function.
0
intheCommented:
ok cheers to both of you :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.