在启动时挂起Windows 10应用商店 [英] Suspend Windows 10 Store App on launch

查看:163
本文介绍了在启动时挂起Windows 10应用商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a tool in C++ to help debug and test deployed Windows 10 Store Apps. One of the problems I've run into is that I need a way to launch a Store App in a suspended state so I can attach a debugger before the app initializes. The usual way I know of to do something like this would be to set a hook on process creation in the parent process and forcibly flag the created process to start in a suspended state; however, for Store Apps, the parent process that creates the actual app process is svchost.exe which runs at a system level and can't be hooked without a kernel-mode driver of some sort.

我使用 IApplicationActivationManager 接口启动应用程序,并使用 IPackageDebugSettings 接口来控制/启动后调试它们。有没有办法我可以暂停一个Windows 10商店应用程序启动时,它不允许首先初始化?

I am using the IApplicationActivationManager interface to launch applications, and am using the IPackageDebugSettings interface to control/debug them after launch. Is there a way I can suspend a Windows 10 Store App when it launches so that it isn't allowed to first initialize?

推荐答案

回头看,我几乎在问题本身内回答了我自己的问题。要在暂停状态下启动Windows 10商店应用程序,请使用 IPackageDebugSettings :: EnableDebugging 方法将可执行文件设置为调试器。正在调试的应用程序将自动启动;

Looking back, I nearly answered my own question within the question itself. To launch a Windows 10 Store app in a suspended state, use the IPackageDebugSettings::EnableDebugging method to set an executable as a debugger. The app being debugged will launch suspended automatically; it's then the debugger's responsibility to resume the app.

我最终在我的项目中做的事情类似于:

What I ended up doing in my project is something akin to this:

// 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商店应用程序,使整个过程更容易。

I wrote a basic wrapper for IPackageDebugSettings as well as a few utility functions for dealing with Windows 10 Store apps to make the overall process easier.

这篇关于在启动时挂起Windows 10应用商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆