Delphi 10附带了转换为Pascal的Windows RT标头。基于this C++ code我试图枚举Windows 8+中所有已安装的Metro应用程序。唯一的问题是,我不知道如何正确地从IIterable_1__IPackage
获得迭代器。 FindPackages
的{{1}}方法被正确调用,我可以通过扫描内存进程(方法调用之前和之后)来确认它。进程内存包含Microsoft.SkypeApp等字符串,因此可以对包进行迭代。一旦我将Deployment_IPackageManager
设置为第一个包,它就会变为无效指针值(在我的PC上为3美元)。我现在想知道,如果它与Delphi中不正确的RT头有关,或者我以错误的方式接近迭代过程(最有可能)。目前的代码:
IIterator_1__IPackage
我没有在program PackagesManager;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Winapi.Windows,
System.SysUtils,
WinAPi.Management,
WinApi.ApplicationModel,
WinApi.WinRT,
System.Win.ComObj;
var
LClassId: HString;
pInspectable: IInspectable;
pAct: IActivationFactory;
packageManager: Deployment_IPackageManager;
pkgs: IIterable_1__IPackage;
pIter: IIterator_1__IPackage;
hasCurrent: Boolean;
packageId: IPackageId;
package: IPackage;
begin
// COM/Runtime Object Initialization
OleCheck(RoInitialize(RO_INIT_SINGLETHREADED));
try
if Succeeded(WindowsCreateString(PWideChar(SDeployment_PackageManager),
Length(SDeployment_PackageManager), LClassId)) then
begin
// Get the activation factory
OleCheck(RoGetActivationFactory(LClassId, IActivationFactory,
pInspectable));
// Activate or create an instance from the Activation Factory
pAct := pInspectable as IActivationFactory;
pAct.ActivateInstance(pInspectable);
// Extract the PackageManager via QueryInterface
OleCheck(pInspectable.QueryInterface(Deployment_IPackageManager,
packageManager));
// Get the `IIterable` Collection of all packages
//
// after below call, process memory contains strings with package names
// i.e. Microsoft.SkypeApp, it means FindPackages was called properly
// confirmed this by scanning process memory for known strings,
// before and after FindPackages call
pkgs := packageManager.FindPackages;
// Get the Iterator from the IIterable
pIter := pkgs.First; // pIter is now $00000003...
hasCurrent := pIter.HasCurrent; // obviously Access Violation
while hasCurrent do
begin
package := pIter.Current;
packageId := package.Id;
hasCurrent := pIter.MoveNext;
end;
end;
finally
RoUninitialize;
end;
end.
解决方案中寻找读取注册表或设置NTFS访问权限,因为这只是项目的基础,可以扩展功能。能够列出所有优雅和包装的包装微软设计的方式将是一个很好的开始。