View Issue Details

IDProjectCategoryView StatusLast Update
0005092JEDI Code LibraryJclSysInfopublic2011-08-23 21:58
ReportergrubsteAssigned Tooutchy 
PrioritynormalSeverityminorReproducibilitysometimes
Status resolvedResolutionfixed 
PlatformOSWindows XP ProOS VersionSP3
Product VersionVersion 2.2 
Target VersionFixed in VersionVersion 2.3 
Summary0005092: GetDomainName returns local computer name in workgroup
DescriptionGetDomainName returns the local computer name if the computer is part of a workgroup.
This might be related to the fix in 0005034.
Additional InformationIn case the computer is part of a domain the function works fine.
TagsNo tags attached.
Fixed in GIT commit
Fixed in SVN revision3587
IDE versionDelphi/C++Builder 2010

Relationships

child of 0005034 resolvedoutchy Result of GetDomainName is not reliable 

Activities

outchy

2010-01-06 14:44

administrator   ~0017071

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.

grubste

2010-01-06 14:52

reporter   ~0017072

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

outchy

2010-01-06 15:22

administrator   ~0017073

Ok, so we need a new function to return the workgroup name. The API NetWkstaGetInfo might be of use there.

grubste

2010-01-06 15:26

reporter   ~0017074

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;

outchy

2010-01-06 15:33

administrator   ~0017075

Would you donate this function to the JCL?
Note that we will likely drop the support for Win 9X.

grubste

2010-01-06 15:40

reporter   ~0017076

I'm not the creator/owner of this code myself, but actually I cannot remember where I got it from...

grubste

2010-01-06 15:44

reporter   ~0017077

Originally it seems to come from Torry's Delphi Pages:

http://www.swissdelphicenter.ch/torry/showcode.php?id=1142

outchy

2011-08-18 07:43

administrator   ~0018882

I added JclSysInfo.GetWorkGroupName in revision 3587.

grubste

2011-08-23 20:50

reporter   ~0018886

Thanks for adding this, it works fine for me in a workgroup and in a domain.
Could be closed...

Issue History

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