View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0005092 | JEDI Code Library | JclSysInfo | public | 2010-01-06 10:13 | 2011-08-23 21:58 |
Reporter | grubste | Assigned To | outchy | ||
Priority | normal | Severity | minor | Reproducibility | sometimes |
Status | resolved | Resolution | fixed | ||
Platform | OS | Windows XP Pro | OS Version | SP3 | |
Product Version | Version 2.2 | ||||
Target Version | Fixed in Version | Version 2.3 | |||
Summary | 0005092: GetDomainName returns local computer name in workgroup | ||||
Description | GetDomainName returns the local computer name if the computer is part of a workgroup. This might be related to the fix in 0005034. | ||||
Additional Information | In case the computer is part of a domain the function works fine. | ||||
Tags | No tags attached. | ||||
Fixed in GIT commit | |||||
Fixed in SVN revision | 3587 | ||||
IDE version | Delphi/C++Builder 2010 | ||||
|
Domain <> Workgroup: a domain is an unified authentication system while a workgroup is just a group a independent computers, each one having its own authentication system. When a computer is not a member of a domain, this function should return the local computer name, workgroups has nothing to do there. |
|
OK, if that is the exact definition for that... I had expected to get the workgroup name back as this is configured in the computer in a similar way as the domain. Even the Windows explorer handles them equivalently (ie. it shows them under "Microsoft Windows Network" independently from being in a workgroup or a domain). |
|
Ok, so we need a new function to return the workgroup name. The API NetWkstaGetInfo might be of use there. |
|
Here's a function that I have used in the past (and that I wanted to swap for the one from JCL, which unfortunately gave different results): function GetDomainName: string; type WKSTA_INFO_100 = record wki100_platform_id : Integer; wki100_computername : PWideChar; wki100_langroup : PWideChar; wki100_ver_major : Integer; wki100_ver_minor : Integer; end; WKSTA_USER_INFO_1 = record wkui1_username : PChar; wkui1_logon_domain : PChar; wkui1_logon_server : PChar; wkui1_oth_domains : PChar; end; //Win9X ANSI prototypes from RADMIN32.DLL and RLOCAL32.DLL TWin95_NetUserGetInfo = function(ServerName, UserName: PChar; Level: DWORD; var BfrPtr: Pointer):Integer; stdcall; TWin95_NetApiBufferFree = function(BufPtr: Pointer):Integer; stdcall; TWin95_NetWkstaUserGetInfo = function(Reserved: PChar; Level: Integer; var BufPtr: Pointer):Integer; stdcall; //WinNT UNICODE equivalents from NETAPI32.DLL TWinNT_NetWkstaGetInfo = function(ServerName: PWideChar; level: Integer; var BufPtr: Pointer):Integer; stdcall; TWinNT_NetApiBufferFree = function(BufPtr: Pointer):Integer; stdcall; var Win95_NetUserGetInfo : TWin95_NetUserGetInfo; Win95_NetWkstaUserGetInfo: TWin95_NetWkstaUserGetInfo; Win95_NetApiBufferFree : TWin95_NetApiBufferFree; WinNT_NetWkstaGetInfo : TWinNT_NetWkstaGetInfo; WinNT_NetApiBufferFree : TWinNT_NetApiBufferFree; WSNT: ^WKSTA_INFO_100; WS95: ^WKSTA_USER_INFO_1; EC: DWORD; hNETAPI: THandle; begin Result := ''; try if IsWinNT then begin hNETAPI := LoadLibrary('NETAPI32.DLL'); if hNETAPI <> 0 then begin @WinNT_NetWkstaGetInfo := GetProcAddress(hNETAPI, 'NetWkstaGetInfo'); @WinNT_NetApiBufferFree := GetProcAddress(hNETAPI, 'NetApiBufferFree'); EC := WinNT_NetWkstaGetInfo(nil, 100, Pointer(WSNT)); if EC = 0 then begin Result := WideCharToString(WSNT^.wki100_langroup); WinNT_NetApiBufferFree(Pointer(WSNT)); end; end; end else begin hNETAPI := LoadLibrary('RADMIN32.DLL'); if hNETAPI <> 0 then begin @Win95_NetApiBufferFree := GetProcAddress(hNETAPI, 'NetApiBufferFree'); @Win95_NetUserGetInfo := GetProcAddress(hNETAPI, 'NetUserGetInfoA'); EC := Win95_NetWkstaUserGetInfo(nil, 1, Pointer(WS95)); if EC = 0 then begin Result := WS95^.wkui1_logon_domain; Win95_NetApiBufferFree(Pointer(WS95)); end; end; end; finally if hNETAPI <> 0 then FreeLibrary(hNETAPI); end; end; |
|
Would you donate this function to the JCL? Note that we will likely drop the support for Win 9X. |
|
I'm not the creator/owner of this code myself, but actually I cannot remember where I got it from... |
|
Originally it seems to come from Torry's Delphi Pages: http://www.swissdelphicenter.ch/torry/showcode.php?id=1142 |
|
I added JclSysInfo.GetWorkGroupName in revision 3587. |
|
Thanks for adding this, it works fine for me in a workgroup and in a domain. Could be closed... |
Date Modified | Username | Field | Change |
---|---|---|---|
2010-01-06 10:13 | grubste | New Issue | |
2010-01-06 10:13 | grubste | IDE version | => Delphi/C++Builder 2010 |
2010-01-06 14:40 | outchy | Relationship added | child of 0005034 |
2010-01-06 14:44 | outchy | Note Added: 0017071 | |
2010-01-06 14:44 | outchy | Assigned To | => outchy |
2010-01-06 14:44 | outchy | Status | new => feedback |
2010-01-06 14:52 | grubste | Note Added: 0017072 | |
2010-01-06 15:22 | outchy | Note Added: 0017073 | |
2010-01-06 15:26 | grubste | Note Added: 0017074 | |
2010-01-06 15:33 | outchy | Note Added: 0017075 | |
2010-01-06 15:40 | grubste | Note Added: 0017076 | |
2010-01-06 15:44 | grubste | Note Added: 0017077 | |
2011-08-18 07:43 | outchy | Note Added: 0018882 | |
2011-08-23 20:50 | grubste | Note Added: 0018886 | |
2011-08-23 21:58 | outchy | Fixed in revision | => 3587 |
2011-08-23 21:58 | outchy | Status | feedback => resolved |
2011-08-23 21:58 | outchy | Fixed in Version | => Version 2.3 (Subversion repository/Daily zips) |
2011-08-23 21:58 | outchy | Resolution | open => fixed |