Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-08-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
koiji

Cita:
Empezado por koiji
...usted cree que me pueda dar un ejemplo...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ActiveX, ComObj;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    ComboBox1: TComboBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  WMIList : TStringList;

implementation

{$R *.dfm}

// Obtiene Información del Sistema por medio de WMI (Windows Management Instrumentation)
procedure GetSystemInformation(ClassName, NameSpace : String; S : TStrings);
var
   FSWbemLocator : OLEVariant;
   FWMIService : OLEVariant;
   FWbemObjectSet : OLEVariant;
   FWbemObject : OLEVariant;
   oEnum : IEnumvariant;
   iValue : LongWord;
   FProperties : OLEVariant;
   oEnumProp : IEnumvariant;
   iValueProp : LongWord;
   FPropObj : OLEVariant;
   SQLWMI : String;
   AuxString : String;
   i : Integer;

begin;

   SQLWMI := 'SELECT * FROM ' + ClassName;

   FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
   FWMIService := FSWbemLocator.ConnectServer('localhost', NameSpace, '', '');
   FWbemObjectSet := FWMIService.ExecQuery(SQLWMI,'WQL',0);
   oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;

   S.Clear;

   while (oEnum.Next(1, FWbemObject, iValue) = 0) do
   begin

      FProperties   := FWbemObject.Properties_;
      oEnumProp     := IUnknown(FProperties._NewEnum) as IEnumVariant;

      S.BeginUpdate;

      S.Add(StringOfChar('-', 100));

      while oEnumProp.Next(1, FPropObj, iValueProp) = 0 do
      begin

         if VarIsArray(FPropObj.Value) then
         begin
            for i:= VarArrayLowBound(FPropObj.Value,1) to VarArrayHighBound(FPropObj.Value,1) do
               AuxString := AuxString + ' ' + String(FPropObj.Value[i]);

            S.Add(FPropObj.Name + ' : ' + AuxString);
         end
         else if not VarIsNull(FPropObj.Value) then
            S.Add(FPropObj.Name + ' : ' + String(FPropObj.Value))
         else
            S.Add(FPropObj.Name + ' : ' + 'Empty');

         FPropObj := Unassigned;

      end;

      S.Add(StringOfChar('-', 100));

      S.EndUpdate;

      FWbemObject := Unassigned;

   end;

end;

// Inicialización de Clases y Namespaces de Windows Management Instrumentation
procedure TForm1.FormCreate(Sender: TObject);
var
   i : Integer;

begin

   WMIList := TStringList.Create;
   WMIList.Add('Win32_BIOS' + '=' + 'root\CIMV2');
   WMIList.Add('CIM_Processor' + '=' + 'root\CIMV2');
   WMIList.Add('Win32_MotherboardDevice' + '=' + 'root\CIMV2');
   WMIList.Add('Win32_PhysicalMemory' + '=' + 'root\CIMV2');
   WMIList.Add('Win32_USBHub' + '=' + 'root\CIMV2');
   WMIList.Add('Win32_Product' + '=' + 'root\CIMV2');
   WMIList.Add('Win32_CDROMDrive' + '=' + 'root\CIMV2');
   WMIList.Add('Win32_BaseBoard' + '=' + 'root\CIMV2');

   for i := 0 to WMIList.Count - 1 do
      ComboBox1.Items.Add(WMIList.Names[i]);

   Memo1.ScrollBars := ssBoth;

end;

// Obtiene Información del Sistema por medio de WMI
procedure TForm1.Button1Click(Sender: TObject);
var
   ClassName, NameSpace : String;

begin
   ClassName := WMIList.Names[ComboBox1.ItemIndex];
   NameSpace := WMIList.ValueFromIndex[ComboBox1.ItemIndex];
   Button1.Enabled := False;
   GetSystemInformation(ClassName, NameSpace, Memo1.Lines);
   Button1.Enabled := True;
   Memo1.SelStart := 0;
   Memo1.SelLength := 0;
end;

// Libera recursos de la Aplicación
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   WMIList.Free;
   Action := caFree;
end;

end.
El código anterior en Delphi 7 bajo Windows 7 Professional x32, permite obtener información de varias clases de información de Windows por medio de WMI (Windows Management Instrumentation), como se muestra en la siguiente imagen:



Nota: Este ejemplo sigue la misma linea de resolución (Uso de WMI) que origino este hilo.

Revisa la siguiente información:
Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 06-08-2014 a las 03:38:27.
Responder Con Cita
  #2  
Antiguo 06-08-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Casi me olvido...

No me hubiera perdonado dejar sin mención a la excelente biblioteca de componentes WMI, autoría de nuestro compañero Neftali: GLibWMI

Saludos

Edito: Creo que me pegó el alzheimer... Muy bueno el ejemplo Nelson
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 06-08-2014 a las 05:04:25.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Placa Base Io Varios 3 12-07-2007 19:01:18
Saber el número de ranuras PCI el la placa base serebi Varios 4 07-02-2006 21:17:06
Saber el número de serie de la placa fer21unmsm Varios 3 30-12-2005 18:36:51
Número de Serie HDD en Red ogorut Varios 0 04-12-2003 12:50:40
Fuera de tópico (Placa base) mosorio Varios 3 05-08-2003 13:21:42


La franja horaria es GMT +2. Ahora son las 09:29:45.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi