Last active
October 17, 2019 15:39
-
-
Save Biswa96/7cb37fdb9ac33e10ffc6790f3ad80195 to your computer and use it in GitHub Desktop.
New Notepad stub from Windows 10 Insider build 18963
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <stdio.h> | |
#include <appmodel.h> | |
#include <inspectable.h> | |
#include <Shlwapi.h> | |
#ifdef _MSC_VER | |
#pragma comment(lib, "Ole32.lib") | |
#pragma comment(lib, "Shlwapi.lib") | |
#pragma comment(lib, "Shell32.lib") | |
#endif | |
static const GUID CLSID_DesktopAppxActivator = { | |
0x168EB462, | |
0x775F, | |
0x42AE, | |
{ 0x91, 0x11, 0xD7, 0x14, 0xB2, 0x30, 0x6C, 0x2E } }; | |
static const GUID IID_DesktopAppxActivator = { | |
0x72E3A5B0, | |
0x8FEA, | |
0x485C, | |
{ 0x9F, 0x8B, 0x82, 0x2B, 0x16, 0xDB, 0xA1, 0x7F } }; | |
/* COM class from twinui.dll */ | |
class IDesktopAppxActivator : public IUnknown | |
{ | |
public: | |
virtual HRESULT Activate( | |
const wchar_t *applicationUserModelId, | |
const wchar_t *packageRelativeExecutable, | |
const wchar_t *arguments, | |
void **processHandle) = 0; | |
virtual HRESULT ActivateWithOptions( | |
const wchar_t *applicationUserModelId, | |
const wchar_t *executable, | |
const wchar_t *arguments, | |
unsigned int options, | |
unsigned int parentProcessId, | |
void **processHandle) = 0; | |
virtual HRESULT ActivateWithOptionsAndArgs( | |
const wchar_t *applicationUserModelId, | |
const wchar_t *executable, | |
const wchar_t *arguments, | |
unsigned int options, | |
unsigned int parentProcessId, | |
IInspectable *activatedEventArgs, | |
void **processHandle) = 0; | |
}; | |
bool WINAPI IsPackageinstalled(PCWSTR packageFamilyName) | |
{ | |
unsigned int count = 0, bufferLength = 0; | |
long res = FindPackagesByPackageFamily( | |
packageFamilyName, | |
240, | |
&count, | |
nullptr, | |
&bufferLength, | |
nullptr, | |
nullptr); | |
if ((!res || res == ERROR_INSUFFICIENT_BUFFER) && count > 0) | |
return true; | |
return false; | |
} | |
HANDLE WINAPI LaunchCentennialAppWithParameters(PCWSTR applicationUserModelId) | |
{ | |
HRESULT hRes; | |
class IDesktopAppxActivator *appxActivate = nullptr; | |
HANDLE processHandle = nullptr; | |
hRes = CoInitialize(nullptr); | |
hRes = CoCreateInstance( | |
CLSID_DesktopAppxActivator, | |
nullptr, | |
CLSCTX_INPROC_SERVER, | |
IID_DesktopAppxActivator, | |
(void **)&appxActivate); | |
const wchar_t *arguments = PathGetArgsW(GetCommandLineW()); | |
hRes = appxActivate->Activate( | |
applicationUserModelId, | |
L"Notepad\\notepad.exe", | |
arguments, | |
&processHandle); | |
if (hRes == ERROR_INSTALL_PACKAGE_NOT_FOUND) | |
wprintf(L"%ls Package was not found.\n", applicationUserModelId); | |
appxActivate->Release(); | |
CoUninitialize(); | |
return processHandle; | |
} | |
int WINAPI main(void) | |
{ | |
HANDLE hProcess = NULL; | |
if (IsPackageinstalled(L"Microsoft.WindowsNotepad_8wekyb3d8bbwe")) | |
{ | |
hProcess = LaunchCentennialAppWithParameters(L"Microsoft.WindowsNotepad_8wekyb3d8bbwe!App"); | |
WaitForSingleObject(hProcess, INFINITE); | |
return 0; | |
} | |
if (IsPackageinstalled(L"Microsoft.WindowsNotepad.Dev_8wekyb3d8bbwe")) | |
{ | |
hProcess = LaunchCentennialAppWithParameters(L"Microsoft.WindowsNotepad.Dev_8wekyb3d8bbwe!App"); | |
WaitForSingleObject(hProcess, INFINITE); | |
return 0; | |
} | |
ShellExecuteW( | |
nullptr, | |
nullptr, | |
L"ms-windows-store://pdp/?PFN=Microsoft.WindowsNotepad_8wekyb3d8bbwe", | |
nullptr, | |
nullptr, | |
SW_SHOWNORMAL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@WalkingCat small gift...