Ktoś moze mi podpowiedzieć jak odczytać właściwości obiektu za pomocą WMI iw DELPHI ?
**Problemy zaczynaja sie w momencie gdy metoda (w moim przypadku GetExclusions) zwraca tablice obiektów i chce odczytać właściwość jednego z tych obiektów (dokladnie to RegistryKey) **
Dokonalem drobnego odkrycia analizując skrypt w powershellu i powstala wersja "002"
Wersja 002 nadal nie działa "Invalid variant operation" ale jest bliżej kodu powershell-a
Cały kod powershell
$COMPUTER = "EMBEDDEDDEVICE"
$NAMESPACE = "root\standardcimv2\embedded"
# Define common parameters
#$CommonParams = @{"namespace"=$NAMESPACE; "computer"=$COMPUTER}
$CommonParams = @{"namespace"=$NAMESPACE}
function Get-RegistryExclusions() {
# This function lists the UWF registry exclusions, both
# for the current session as well as the next session after a restart.
# Get the UWF_RegistryFilter configuration for the current session
$currentConfig = Get-WMIObject -class UWF_RegistryFilter @CommonParams |
where {
$_.CurrentSession -eq $true
};
# Display registry exclusions for the current session
if ($currentConfig) {
Write-Host ""
Write-Host "The following registry entries are currently excluded from UWF filtering:";
$currentExcludedList = $currentConfig.GetExclusions()
if ($currentExcludedList.ExcludedKeys) {
foreach ($registryExclusion in $currentExcludedList.ExcludedKeys) {
Write-Host " " $registryExclusion.RegistryKey
}
} else {
Write-Host " None"
}
} else {
Write-Error "Could not retrieve UWF_RegistryFilter.";
}
Get-RegistryExclusions
// wersja 001 nie dzialajaca !!!
var
wynik: Integer;
FWbemObjectExclusions : OLEVariant;
begin
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\StandardCimv2\embedded', WbemUser, WbemPassword);
FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM UWF_RegistryFilter','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Writeln(Format('CurrentSession %s',[String(FWbemObject.CurrentSession)]));// Boolean
Writeln(Format('PersistDomainSecretKey %s',[String(FWbemObject.PersistDomainSecretKey)]));// Boolean
Writeln(Format('PersistTSCAL %s',[String(FWbemObject.PersistTSCAL)]));// Boolean
Writeln('');
wynik := FWbemObject.GetExclusions(FWbemObjectExclusions);
Writeln('Wynik=',FWbemObjectExclusions[0].RegistryKey ); // i TUTAJ juz nie wiem jak odczytać RegistryKey !!!
end;
var
wynik: OLEVariant;
begin
// wersja 002
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\StandardCimv2\embedded', WbemUser, WbemPassword);
FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM UWF_RegistryFilter','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Writeln(Format('CurrentSession %s',[String(FWbemObject.CurrentSession)]));// Boolean
Writeln(Format('PersistDomainSecretKey %s',[String(FWbemObject.PersistDomainSecretKey)]));// Boolean
Writeln(Format('PersistTSCAL %s',[String(FWbemObject.PersistTSCAL)]));// Boolean
Writeln('');
wynik := FWbemObject.GetExclusions();
Writeln(wynik.ExcludedKeys[0].RegistryKey); // wyjatek "Invalid variant operation"
end;
Dokumentacja do klas WMI
https://docs.microsoft.com/en-us/windows-hardware/customize/enterprise/uwf-registryfiltergetexclusions
https://docs.microsoft.com/en-us/windows-hardware/customize/enterprise/uwf-excludedregistrykey
W WmiExplorer widze ze sa dane w zwracanych obiektach
Do generowania kodu uzylem wmi-delphi-code-creator