gpt4 book ai didi

c++ - 在启动时暂停 Windows 10 应用商店应用程序

转载 作者:行者123 更新时间:2023-11-28 05:49:12 24 4
gpt4 key购买 nike

我正在用 C++ 编写一个工具来帮助调试和测试已部署的 Windows 10 应用商店应用程序。我遇到的一个问题是我需要一种方法来启动处于挂起状态的商店应用程序,以便我可以在应用程序初始化之前附加调试器。我知道做这样的事情的通常方法是在父进程中设置进程创建的钩子(Hook),并强制标记创建的进程以挂起状态启动;然而,对于商店应用程序,创建实际应用程序进程的父进程是 svchost.exe,它在系统级别运行,并且在没有某种内核模式驱动程序的情况下无法 Hook 。

我正在使用 IApplicationActivationManager 界面来启动应用程序,并在启动后使用 IPackageDebugSettings 界面来控制/调试它们。有什么方法可以在 Windows 10 应用商店应用程序启动时将其暂停,从而不允许它首先进行初始化?

最佳答案

回想起来,我几乎在问题本身中回答了我自己的问题。要以暂停状态启动 Windows 10 应用商店应用,请使用 IPackageDebugSettings::EnableDebugging将可执行文件设置为调试器的方法。正在调试的应用程序将自动暂停启动;然后由调试器负责恢复应用程序。

我最终在我的项目中所做的类似于此:

// Gets the current application's UserModelId and PackageId from the registry
std::wstring appName = AppUtils::GetApplicationUserModelId();
std::wstring appFullName = AppUtils::GetApplicationPackageId();

HRESULT hResult = S_OK;

// Create a new instance of IPackageDebugSettings
ATL::CComQIPtr<IPackageDebugSettings> debugSettings;
hResult = debugSettings.CoCreateInstance(CLSID_PackageDebugSettings, NULL, CLSCTX_ALL);
if(hResult != S_OK) return hResult;

// Enable debugging and use a custom debugger
hResult = debugSettings->EnableDebugging(appFullName.c_str(), pathToDebugger.c_str(), NULL);
if(hResult != S_OK) return hResult;

// Launch the application
DWORD dwProcessId = 0;
hResult = AppUtils::LaunchApplication(appName, &dwProcessId);
if(hResult != S_OK) return hResult;

/* Do more stuff after the app has been resumed by the debugger */

// Stop debugging the application so it can run as normal
hResult = debugSettings->DisableDebugging(appFullName.c_str());
if(hResult != S_OK) return hResult;

我为 IPackageDebugSettings 写了一个基本包装器以及一些用于处理 Windows 10 应用商店应用程序的实用函数,以简化整个过程。

关于c++ - 在启动时暂停 Windows 10 应用商店应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35612194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com