1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| // Fonction lecture infos WMI
// InfoWMI('Nom de l'instance Win32_...', 'Nom de la propriété')
function InfoWMI(Instance, Properties : String) :TStringList;
var
WmiLocator: TSWbemLocator;
WmiService: SWbemServices;
WmiObjectSet: SWbemObjectSet;
WmiObject: SWbemObject;
//WmiProperty: SWbemProperty;
ObjectEnumerator: IEnumVariant;
ArrayVariant: OleVariant;
NumberItem: LongWord;
begin
result := TStringList.create;
DNS2 := TStringList.create;
WmiLocator:= TSWbemLocator.Create(nil);
try
Screen.Cursor := crAppStart;
// Connexion WMI (PCName, 'ROOT\CIMV2', UserName, UserPassword, '', '', ...)
WmiService:= WMILocator.ConnectServer(sPCName, 'ROOT\CIMV2', sUserName, sUserPwd, '',
'', wbemConnectFlagUseMaxWait, nil);
WmiObjectSet := WmiService.InstancesOf(Instance,
wbemFlagReturnWhenComplete, nil);
// Affecte un énumérateur pour la collection d'objet SWbemObject
ObjectEnumerator:= (WmiObjectSet._NewEnum) as IEnumVariant;
// Retourne NumberItem éléments dans le tableau ArrayVariant
while (ObjectEnumerator.Next(1, ArrayVariant, NumberItem) = S_OK) do
begin
// Récupére de la collection l'objet SWbemObject courant
WmiObject := IUnknown(ArrayVariant) as SWBemObject;
If WmiObject.Properties_.Item(Properties,0) <> nil Then
begin
if not VarIsNull(WmiObject.Properties_.Item(Properties, 0).Get_Value) Then
begin
if WmiObject.Properties_.Item(Properties,0).IsArray Then
begin
if not VarArrayHighBound(WmiObject.Properties_.Item(Properties,0).Get_Value, 1) > 0 Then
begin
// Retrouve la propriétés de l'instance au format MOF
result.add(WmiObject.Properties_.Item(Properties,0).Get_Value[0]);
if(Properties = 'DNSServerSearchOrder') Then DNS2.add('');
end
else
begin
result.add(WmiObject.Properties_.Item(Properties,0).Get_Value[0]);
if(Properties = 'DNSServerSearchOrder') Then
begin
if VarArrayDimCount(WmiObject.Properties_.Item(Properties,0).Get_Value) > 0 Then
DNS2.add(WmiObject.Properties_.Item(Properties,0).Get_Value[1])
else DNS2.add('');
end;
end;
end
else
begin
// Retrouve la propriétés de l'instance au format MOF
result.add(WmiObject.Properties_.Item(Properties,0).Get_Value)
end;
end
else
begin
result.add('');
if(Properties = 'DNSServerSearchOrder') Then DNS2.add('');
end;
end;
end;
Screen.Cursor:= crDefault;
Finally;
WmiLocator.Disconnect;
WmiLocator.Free;
end;
end; |
Partager