2004. november 11., csütörtök

Getting network workgroup name


Problem/Question/Abstract:

How to get network workgroup name

Answer:

I reently noticed that the question "how to find out what's the network workgroup" was being constantly asked. As I had already had the same question and figured it out by myself, I wrote a little function that will do the trick. The trick here consists in reading the "Workgroup" string from the 'System\CurrentControlSet\Services\VxD\VNETSUP' key in the registry (under HKEY_LOCAL_MACHINE). Anyway, here's a shortened (but working) version of the routine I came up with. Note that if the workgroup name can't be retrieved - for any reason - the string '(n/a)' will be returned, standing for 'not available'.

function GetNetWorkgroup: string;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.create;
  Result := '(n/a)';
  with Reg do
  try
    RootKey := HKEY_LOCAL_MACHINE;
    if OpenKey('System\CurrentControlSet\Services\VxD\VNETSUP',
      false) then
      Result := ReadString('Workgroup');
  finally
    CloseKey;
    free;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése