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 ??
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 ??
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
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Aaah, Barry, just there with the right source in the right moment :-))
Ciao, Mike
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(NetWkstaUserGetIn fo) 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
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(NetWkstaUserGetIn
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
ASKER
Thanks Barry, that's it.
I didn't know how to call that function.
I didn't know how to call that function.
ok cheers to both of you :-)
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