在启动时暂停 Windows 10 个商店应用程序
Suspend Windows 10 Store App on launch
我正在用 C++ 编写一个工具来帮助调试和测试已部署的 Windows 10 个商店应用程序。我 运行 遇到的一个问题是,我需要一种方法来以挂起状态启动商店应用程序,以便我可以在应用程序初始化之前附加调试器。我知道做这样的事情的通常方法是在父进程中设置进程创建的钩子,并强制标记创建的进程以挂起状态启动;但是,对于商店应用程序,创建实际应用程序进程的父进程是 svchost.exe,它 运行 在系统级别,如果没有某种内核模式驱动程序就无法挂钩。
我正在使用 IApplicationActivationManager
界面启动应用程序,并在启动后使用 IPackageDebugSettings
界面 control/debug 它们。有什么方法可以让 Windows 10 Store 应用程序在启动时暂停,这样就不允许它首先初始化?
在 Visual Studio 中转到项目的属性。然后进入“调试”选项卡和 select 'Do not launch, but debug my code when it starts'。
这是您要找的吗?
回想起来,我几乎在问题本身中回答了我自己的问题。要在暂停状态下启动 Windows 10 Store 应用程序,请使用 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 个商店应用程序。我 运行 遇到的一个问题是,我需要一种方法来以挂起状态启动商店应用程序,以便我可以在应用程序初始化之前附加调试器。我知道做这样的事情的通常方法是在父进程中设置进程创建的钩子,并强制标记创建的进程以挂起状态启动;但是,对于商店应用程序,创建实际应用程序进程的父进程是 svchost.exe,它 运行 在系统级别,如果没有某种内核模式驱动程序就无法挂钩。
我正在使用 IApplicationActivationManager
界面启动应用程序,并在启动后使用 IPackageDebugSettings
界面 control/debug 它们。有什么方法可以让 Windows 10 Store 应用程序在启动时暂停,这样就不允许它首先初始化?
在 Visual Studio 中转到项目的属性。然后进入“调试”选项卡和 select 'Do not launch, but debug my code when it starts'。
这是您要找的吗?
回想起来,我几乎在问题本身中回答了我自己的问题。要在暂停状态下启动 Windows 10 Store 应用程序,请使用 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 个商店应用程序的实用函数,以使整个过程更容易。