I have spent several hours on the internet trying to answer this question
alone with no success.
> Question: How do I find the computer's workgroup name?
The workgroup is returned by the NetServerGetInfo API if you request
the domain name, and the PC is not a member of a domain.
It's easiest to use Colin Wilson's NT LAN Manager components from:
http://www.wilsonc.demon.co.uk/delphi_6.htm
Angus
A MSDN search also turned up a function in the network management API:
NetGetJoinInformation. Like many others of this group of API functions it is
not available on Win9x platforms (although the LAN manager API there may
have a similar function). The JwaLMJoin unit of the JEDI API translation
contains the required declarations.
Then there is the registry. This is notoriously platform-dependent as well,
so you need to check on all platforms you need to support if the key names
are the same there. There used to be a website dedicated to the secrets of
the Windows registry, www.regedit.com or .org i think, may be worth a
trawl...
On Win2K, for example, i see a key
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
which contains a value "Last Domain", which contains the workgroup name
together with some numeric values that probably distinguish domain logins
from workgroup membership. (The value is "0,2,WORKGROUP" on my home PC).
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
type
WKSTA_INFO_100 = Record
wki100_platform_id : DWORD;
wki100_computername : LPWSTR;
wki100_langroup : LPWSTR;
wki100_ver_major : DWORD;
wki100_ver_minor : DWORD;
End;
LPWKSTA_INFO_100 = ^WKSTA_INFO_100;
function GetNetParam(AParam : integer) : string;
Var
PBuf : LPWKSTA_INFO_100;
Res : LongInt;
begin
result := '';
Res := NetWkstaGetInfo (Nil, 100, @PBuf);
If Res = NERR_Success Then
begin
case AParam of
0: Result := string(PBuf^.wki100_computername);
1: Result := string(PBuf^.wki100_langroup);
end;
end;
end;
// Following function returns the name of the local computer:
function GetTheComputerName : string;
begin
Result := GetNetParam(0);
end;
//Following function returns the name of the domain to which the computer
belongs:
function GetTheDomainName : string;
begin
Result := GetNetParam(1);
end;
//You must be a member of the Administrators local group to successfully
//execute NetWkstaSetInfo on a remote server or on a computer that has
//local security enabled.
cheers,
Paul.
<SNIP>
"Ace" <askaqu...@rogers.vom> wrote in message
news:42fa...@newsgroups.borland.com...
Function GetCurrentUserAndDomain(Var strUser : String; Var strDomain :
String) : Boolean;
Type
PTOKEN_USER = ^TOKEN_USER;
_TOKEN_USER = record
User : TSidAndAttributes;
end;
TOKEN_USER = _TOKEN_USER;
Var hToken : THandle;
Var cbBuf : Cardinal;
var ptiUser : PTOKEN_USER;
Var snu : SID_NAME_USE;
Var chUser : Cardinal;
Var chDomain : Cardinal;
Var szUser : pChar;
Var szDomain : pChar;
Begin
Result := False;
If NOT OpenThreadToken(GetCurrentThread,TOKEN_QUERY,true,hToken) Then
Begin
If (GetLastError <> ERROR_NO_TOKEN) Then Exit;
If NOT (OpenProcessToken(GetCurrentProcess,TOKEN_QUERY,hToken)) Then
Exit;
End;
If NOT (GetTokenInformation(hToken, TokenUser, nil, 0, cbBuf)) Then
If (GetLastError <> ERROR_INSUFFICIENT_BUFFER) Then
Begin
CloseHandle(hToken);
exit;
end;
If (cbBuf = 0) Then Exit;
chDomain := 50;
chUser := 50;
GetMem(ptiUser,cbBuf);
GetMem(szDomain,chDomain);
GetMem(szUser,chUser);
If GetTokenInformation(hToken,TokenUser,ptiUser,cbBuf,cbBuf) Then
Begin
If
(LookupAccountSid(nil,ptiUser.User.Sid,szUser,chUser,szDomain,chDomain,snu))
Then
Begin
Result := True;
strUser := StrPas(szUser);
strDomain := StrPas(szDomain);
End;
End;
CloseHandle(hToken);
FreeMem(ptiUser);
FreeMem(szDomain);
FreeMem(szUser);
End;
"David" <spam...@localhost.org> wrote in message
news:42fb2b5d$1...@newsgroups.borland.com...