• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • Last Modified:

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 ??
0
Tulip
Asked:
Tulip
  • 3
  • 3
  • 2
  • +1
1 Solution
 
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now