Unconfigured Ad Widget

Collapse

Anúncio

Collapse
No announcement yet.

Obtendo Informacoes do Sistema

Collapse
X
 
  • Filter
  • Tempo
  • Show
Clear All
new posts

  • Font Size
    #1

    Tutorial Obtendo Informacoes do Sistema

    Amigos, venho postar para voces mais um topico sobre delphi, neste vou ensinar algumas funcoes que podem usar para capturar informacoes do computador e do sistema operacional em delphi, ok, vamos la =DD

    Obtendo o tipo de sistema operacional

    Código:
    function PegarOs: String;
    var
      PlatformId, VersionNumber: string;
      CSDVersion: String;
    begin
      CSDVersion := '';
    
      // Detecta Plataforma
      case Win32Platform of
        // Teste para familia do windows 95,9X
        VER_PLATFORM_WIN32_WINDOWS:
        begin
          if Win32MajorVersion = 4 then
            case Win32MinorVersion of
              0:  if (Length(Win32CSDVersion) > 0) and
                     (Win32CSDVersion[1] in ['B', 'C']) then
                    PlatformId := '95 OSR2'
                  else
                    PlatformId := '95';
              10: if (Length(Win32CSDVersion) > 0) and
                     (Win32CSDVersion[1] = 'A') then
                    PlatformId := '98 SE'
                  else
                    PlatformId := '98';
              90: PlatformId := 'ME';
            end
          else
            PlatformId := '9x version (unknown)';
        end;
       //Teste para familia NT
        VER_PLATFORM_WIN32_NT:
        begin
          if Length(Win32CSDVersion) > 0 then CSDVersion := Win32CSDVersion;
          if Win32MajorVersion <= 4 then
            PlatformId := 'NT'
          else
            if Win32MajorVersion = 5 then
              case Win32MinorVersion of
                0: PlatformId := '2000';
                1: PlatformId := 'XP';
                2: PlatformId := 'Server 2003';
              end
            else if (Win32MajorVersion = 6) and (Win32MinorVersion = 0) then
              PlatformId := 'Vista'
            else
              PlatformId := 'Windows 7';
        end;
      end;
      Result :=PlatformId;
    end;
    Autor: TGA

    Verificando se o usuario possui privilegios administrativos
    Código:
    function AdminPriv: Boolean;
    const
    AUTORIDADE_NT_SYSTEM: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
    SECURITY_BUILTIN_DOMAIN_RID = $00000020;
    DOMAIN_ALIAS_RID_ADMINS = $00000220;
    var
    x: Integer;
    hMascara_acesso: THandle;
    conseguiu: BOOL;
    dwInfoBufferSize: DWORD;
    AdminPSID: PSID;
    gruposp: PTokenGroups;
    begin
    Result   := False;
    conseguiu := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,hMascara_acesso);
    if not conseguiu then
    begin
    if GetLastError = ERROR_NO_TOKEN then
    conseguiu := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,hMascara_acesso);
    end;
    if conseguiu then
    begin
    GetMem(gruposp, 1024);
    conseguiu := GetTokenInformation(hMascara_acesso, TokenGroups,gruposp, 1024, dwInfoBufferSize);
    CloseHandle(hMascara_acesso);
    if conseguiu then
    begin
    AllocateAndInitializeSid(AUTORIDADE_NT_SYSTEM, 2,SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, AdminPSID);
    {$R-}
    for x := 0 to gruposp.GroupCount - 1 do
    if EqualSid(AdminPSID, gruposp.Groups[x].Sid) then
    begin
    Result := True;
    Break;
    end;
    {$R+}
    FreeSid(AdminPSID);
    end;
    FreeMem(gruposp);
    end;
    end;
    Autor: TGA/Con§T4nT1nO


    Obtendo Nome do usuario Logado
    Código:
    function NomeUsuario: String;
    var
    Usuario: Pchar;
    Tamanho: Cardinal;
    begin
    Result := '';
    Tamanho := 100;
    Getmem(usuario, Tamanho);
    GetUserName(Usuario, Tamanho);
    Result := Usuario;
    FreeMem(usuario);
    end;
    Autor: TGA


    Obtendo Nome do Computador
    Código:
    function Nomepc: String;
    var
    PC: Pchar;
    Tamanho: Cardinal;
    begin
    Result := '';
    Tamanho := 100;
    Getmem(PC, Tamanho);
    GetComputerName(PC, Tamanho);
    Result := PC;
    FreeMem(PC);
    end;
    Autor: TGA

    Obtendo Serial do Disco
    Código:
    Function SerialDisco(Disco: String): String;
    Var
    Serial:DWord;
    DirLen,Flags: DWord;
    DLabel : Array[0..11] of Char;
    begin
    Result := '';
    GetVolumeInformation(PChar(disco),dLabel,12,@Serial,DirLen,Flags,nil,0);
    Result := IntToHex(Serial,8);
    end;
    Autor: TGA


    Obtendo MacAddress
    Código:
    Function MacAddress: string;
    var
    ID1, ID2: TGUID;
    apiFunc:Function(GUID: PGUID): Longint; stdcall;
    dll:cardinal;
    begin
    Result := '';
    dll := LoadLibrary('rpcrt4.dll');
    if dll <> 0 then
    begin
    @apiFunc := GetProcAddress(dll, 'UuidCreateSequential');
    if Assigned(apiFunc) then
    begin
    if (apiFunc(@ID1) = 0) and
    (apiFunc(@ID2) = 0) and
    (ID1.D4[2] = ID2.D4[2]) and
    (ID1.D4[3] = ID2.D4[3]) and
    (ID1.D4[4] = ID2.D4[4]) and
    (ID1.D4[5] = ID2.D4[5]) and
    (ID1.D4[6] = ID2.D4[6]) and
    (ID1.D4[7] = ID2.D4[7]) then
    begin
    Result :=
    IntToHex(ID1.D4[2], 2) + '-' +
    IntToHex(ID1.D4[3], 2) + '-' +
    IntToHex(ID1.D4[4], 2) + '-' +
    IntToHex(ID1.D4[5], 2) + '-' +
    IntToHex(ID1.D4[6], 2) + '-' +
    IntToHex(ID1.D4[7], 2);
    end;
    end;
    end;
    end;
    Autor:TGA/DarkLordn


    Obtendo Resolucao

    Código:
    Function Resolucao() : String;
    var W,h:String;
    begin
    w := INtTOStr(screen.Width);
    h := IntToStr(screen.Height);
    Result := w+' x '+h;
    end;
    Autor:TGA

  • Font Size
    #2
    boa dica ^^

    vlw ae,

    Comment


    • Font Size
      #3
      Obrigado por compartilhar.
      sigpic

      Comment


      • Font Size
        #4
        Boa dica ;D
        Mais eu só tenho uma dúvida.
        Se eu quiser por isso em um ListView ou ListBox como faço?

        Comment

        X
        Working...
        X