Search code examples
windowsvbscriptinno-setupadministrator

How to get administrator group name in different languages


I'm developing a installer using Inno Setup, and I need to create a windows user with administrator privileges, I can do it normaly using this command: net localgroup administrators USER /add

But there's a problem... if I execute this on a non-english Windows, the "administrators", group will not exists, aka: if installing on pt-br Windows it will be called "Administradores".

I was wondering if there's a windows variable wich store the admin group name.

Note that using Inno Setup i'm able to use vbs scripts.


Solution

  • I did a function to Inno Setup, also, I guess it will works for Delphi.

    Complete list of SID's: http://support.microsoft.com/kb/243330/en

    Tks @nlsbshtr

    function GetNameBySID(const SID: string): string;
    var
      WbemLocator, WbemServices, WbemService, WbemObjectSets: Variant;
    begin;
      Result := '';
      WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      WbemServices := WbemLocator.ConnectServer('localhost', 'root\CIMV2');
      WbemObjectSet := WbemServices.ExecQuery('SELECT Name FROM Win32_Group where SID="'+SID+'"');
      if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
      begin        
        WbemObject := WbemObjectSet.ItemIndex(0);
        if not VarIsNull(WbemObject) then
          Result := WbemObject.Name;      
      end;
    end;