Skip to content

Commit 085b461

Browse files
dkbennettSantosh Chintalapatiangelazhangmsft
authored
Installer Launch sample (#117)
* Create the Installer Launch sample * Updating Windows SDK dependency to 10.0.* versions * Incorporate PR feedback * Remove duplicate folder * Remove unused readme file from the project * Relocating ReadMe.Md to parent path * update readme Co-authored-by: Santosh Chintalapati <[email protected]> Co-authored-by: Angela Zhang <[email protected]>
1 parent 9723aeb commit 085b461

File tree

9 files changed

+341
-0
lines changed

9 files changed

+341
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This repository hosts samples for the [Windows App SDK](https://github.com/micro
1515

1616
#### Deployment
1717
- [Deployment Manager](Samples/DeploymentManager): This sample demonstrates how to initialize and access deployment information for the Windows App SDK runtime.
18+
- [Installer](Samples/Installer): This sample demonstrates how to launch the Windows App SDK installer without a console window.
1819
- [Unpackaged](Samples/Unpackaged): These samples demonstrate auto-initialization with the Windows App SDK package from non-MSIX (unpackaged) application.
1920

2021
#### Dynamic Dependencies

Samples/Installer/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
name: "Installer launch sample"
3+
page_type: sample
4+
languages:
5+
- cpp
6+
products:
7+
- windows
8+
- windows-app-sdk
9+
- windows-api-win32
10+
description: "Shows how to use CreateProcess to launch the installer without a console window."
11+
urlFragment: installer
12+
---
13+
# Installer launch sample
14+
15+
This sample demonstrates how to launch the WindowsAppRuntimeInstall.exe without having a pop-up
16+
window appearing while it is running. This sample is intended for Win32 programs which have setup
17+
programs that need to embed the WindowsAppSDK without any pop-up windows.
18+
19+
## Requirements
20+
21+
- This sample requires downloading WindowsAppRuntimeInstall.exe from [here](https://docs.microsoft.com/windows/apps/windows-app-sdk/downloads) or building a version of it.
22+
23+
- This sample assumes that WindowsAppRuntimeInstall.exe will be in %USERPROFILE%\Downloads for convenience.
24+
If a different path is desired, it can be specified in the #define at the top in main.cpp.
25+
26+
- Before building the sample, make sure to set up your environment correctly by following the steps [here](https://docs.microsoft.com/windows/apps/windows-app-sdk/set-up-your-development-environment).
27+
28+
## Building and running any of the samples
29+
30+
1. Download WindowsAppRuntimeInstall.exe from [here](https://docs.microsoft.com/windows/apps/windows-app-sdk/downloads) or build a version of it, and place it in
31+
%USERPROFILE%\Downloads.
32+
2. Open the solution file (.sln) in the sample.
33+
3. Build the solution.
34+
4. Debug the project.
35+
36+
*Caution, this sample will execute whatever executable is at the specified path. It is recommended
37+
to build the Installer with test packages from the WindowsAppSDK project or use a simple "Hello,
38+
World" console application as the executable to avoid modifying the system with the sample.*
39+
40+
## Related Links
41+
42+
- [Creating Processes](https://docs.microsoft.com/windows/win32/procthread/creating-processes)
43+
- [Process Creation Flags](https://docs.microsoft.com/windows/win32/procthread/process-creation-flags)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31702.278
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LaunchInstaller", "LaunchInstaller.vcxproj", "{8BF9A634-D043-4D40-AADC-0752DD634E20}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|ARM64 = Debug|ARM64
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|ARM64 = Release|ARM64
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Debug|ARM64.ActiveCfg = Debug|ARM64
19+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Debug|ARM64.Build.0 = Debug|ARM64
20+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Debug|x64.ActiveCfg = Debug|x64
21+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Debug|x64.Build.0 = Debug|x64
22+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Debug|x86.ActiveCfg = Debug|Win32
23+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Debug|x86.Build.0 = Debug|Win32
24+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Release|ARM64.ActiveCfg = Release|ARM64
25+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Release|ARM64.Build.0 = Release|ARM64
26+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Release|x64.ActiveCfg = Release|x64
27+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Release|x64.Build.0 = Release|x64
28+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Release|x86.ActiveCfg = Release|Win32
29+
{8BF9A634-D043-4D40-AADC-0752DD634E20}.Release|x86.Build.0 = Release|Win32
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {3458DA18-5D03-40E7-B22E-167011B3B54C}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props')" />
4+
<Import Project="..\..\Build.Common.Cpp.props" />
5+
<PropertyGroup Label="Globals">
6+
<CppWinRTOptimized>true</CppWinRTOptimized>
7+
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
8+
<CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata>
9+
<MinimalCoreWin>true</MinimalCoreWin>
10+
<VCProjectVersion>15.0</VCProjectVersion>
11+
<ProjectGuid>{8bf9a634-d043-4d40-aadc-0752dd634e20}</ProjectGuid>
12+
<Keyword>Win32Proj</Keyword>
13+
<RootNamespace>LaunchInstaller</RootNamespace>
14+
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0</WindowsTargetPlatformVersion>
15+
<WindowsTargetPlatformMinVersion>10.0.17763.0</WindowsTargetPlatformMinVersion>
16+
<ProjectName>LaunchInstaller</ProjectName>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19+
<ItemGroup Label="ProjectConfigurations">
20+
<ProjectConfiguration Include="Debug|ARM64">
21+
<Configuration>Debug</Configuration>
22+
<Platform>ARM64</Platform>
23+
</ProjectConfiguration>
24+
<ProjectConfiguration Include="Debug|Win32">
25+
<Configuration>Debug</Configuration>
26+
<Platform>Win32</Platform>
27+
</ProjectConfiguration>
28+
<ProjectConfiguration Include="Release|ARM64">
29+
<Configuration>Release</Configuration>
30+
<Platform>ARM64</Platform>
31+
</ProjectConfiguration>
32+
<ProjectConfiguration Include="Release|Win32">
33+
<Configuration>Release</Configuration>
34+
<Platform>Win32</Platform>
35+
</ProjectConfiguration>
36+
<ProjectConfiguration Include="Debug|x64">
37+
<Configuration>Debug</Configuration>
38+
<Platform>x64</Platform>
39+
</ProjectConfiguration>
40+
<ProjectConfiguration Include="Release|x64">
41+
<Configuration>Release</Configuration>
42+
<Platform>x64</Platform>
43+
</ProjectConfiguration>
44+
</ItemGroup>
45+
<PropertyGroup Label="Configuration">
46+
<ConfigurationType>Application</ConfigurationType>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
49+
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
50+
<UseDebugLibraries>true</UseDebugLibraries>
51+
<LinkIncremental>true</LinkIncremental>
52+
</PropertyGroup>
53+
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
54+
<UseDebugLibraries>false</UseDebugLibraries>
55+
<WholeProgramOptimization>true</WholeProgramOptimization>
56+
<LinkIncremental>false</LinkIncremental>
57+
</PropertyGroup>
58+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
59+
<ImportGroup Label="ExtensionSettings">
60+
</ImportGroup>
61+
<ImportGroup Label="Shared">
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<PropertyGroup Label="UserMacros" />
67+
<ItemDefinitionGroup>
68+
<ClCompile>
69+
<PrecompiledHeader>Use</PrecompiledHeader>
70+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
71+
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
72+
<PreprocessorDefinitions>_CONSOLE;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
73+
<WarningLevel>Level4</WarningLevel>
74+
<AdditionalOptions>%(AdditionalOptions) /permissive- /bigobj</AdditionalOptions>
75+
</ClCompile>
76+
</ItemDefinitionGroup>
77+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
78+
<ClCompile>
79+
<Optimization>Disabled</Optimization>
80+
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
81+
</ClCompile>
82+
<Link>
83+
<SubSystem>Console</SubSystem>
84+
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
85+
</Link>
86+
</ItemDefinitionGroup>
87+
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
88+
<ClCompile>
89+
<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
90+
</ClCompile>
91+
</ItemDefinitionGroup>
92+
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
93+
<ClCompile>
94+
<Optimization>MaxSpeed</Optimization>
95+
<FunctionLevelLinking>true</FunctionLevelLinking>
96+
<IntrinsicFunctions>true</IntrinsicFunctions>
97+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
98+
</ClCompile>
99+
<Link>
100+
<SubSystem>Console</SubSystem>
101+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
102+
<OptimizeReferences>true</OptimizeReferences>
103+
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
104+
</Link>
105+
</ItemDefinitionGroup>
106+
<ItemGroup>
107+
<ClInclude Include="pch.h" />
108+
</ItemGroup>
109+
<ItemGroup>
110+
<ClCompile Include="main.cpp" />
111+
<ClCompile Include="pch.cpp">
112+
<PrecompiledHeader>Create</PrecompiledHeader>
113+
</ClCompile>
114+
</ItemGroup>
115+
<ItemGroup>
116+
<None Include="packages.config" />
117+
</ItemGroup>
118+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
119+
<ImportGroup Label="ExtensionTargets">
120+
<Import Project="packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets')" />
121+
<Import Project="packages\Microsoft.Windows.ImplementationLibrary.1.0.211019.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('packages\Microsoft.Windows.ImplementationLibrary.1.0.211019.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
122+
</ImportGroup>
123+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
124+
<PropertyGroup>
125+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
126+
</PropertyGroup>
127+
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.props'))" />
128+
<Error Condition="!Exists('packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.CppWinRT.2.0.211028.7\build\native\Microsoft.Windows.CppWinRT.targets'))" />
129+
<Error Condition="!Exists('packages\Microsoft.Windows.ImplementationLibrary.1.0.211019.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Windows.ImplementationLibrary.1.0.211019.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
130+
</Target>
131+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="pch.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="pch.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
<ClCompile Include="main.cpp">
27+
<Filter>Source Files</Filter>
28+
</ClCompile>
29+
</ItemGroup>
30+
<ItemGroup>
31+
<None Include="packages.config" />
32+
</ItemGroup>
33+
</Project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#include "pch.h"
5+
6+
using namespace winrt;
7+
using namespace winrt::Windows::Foundation;
8+
using namespace winrt::Windows::Foundation::Collections;
9+
10+
// Assumes the installer exists in the following location.
11+
// It is recommended to use a harmless "Hello, World!" type program, or a test installer built from
12+
// the WindowsAppSDK Installer project. A released WindowsAppRuntimeInstall.exe will also work.
13+
#define INSTALLER_PATH L"%USERPROFILE%\\Downloads\\WindowsAppRuntimeInstall.exe"
14+
15+
// Helper for expanding environment variables for installer path flexibility.
16+
std::filesystem::path ExpandedPath(_In_ PCWSTR unexpandedPath)
17+
{
18+
auto length = ::ExpandEnvironmentStrings(unexpandedPath, nullptr, 0);
19+
THROW_LAST_ERROR_IF(length == 0);
20+
std::wstring expandedPath;
21+
expandedPath.resize(length - 1);
22+
auto expandedLength = ::ExpandEnvironmentStrings(unexpandedPath, expandedPath.data(), length);
23+
THROW_LAST_ERROR_IF(expandedLength == 0 || expandedLength > length);
24+
return std::filesystem::path(expandedPath);
25+
}
26+
27+
int main()
28+
{
29+
init_apartment();
30+
31+
auto installerPath = ExpandedPath(INSTALLER_PATH);
32+
printf("Running installer at %ws\n", installerPath.wstring().c_str());
33+
34+
STARTUPINFO startupInfo{};
35+
startupInfo.cb = sizeof(startupInfo);
36+
PROCESS_INFORMATION processInformation{};
37+
38+
// Create the process using CREATE_NO_WINDOW creation flag.
39+
// This suppresses the console window from being displayed.
40+
// For flag details, see https://docs.microsoft.com/windows/win32/procthread/process-creation-flags
41+
if (!CreateProcessW(
42+
installerPath.wstring().c_str(), // Module name
43+
NULL, // Command line
44+
NULL, // Process handle not inheritable
45+
NULL, // Thread handle not inheritable
46+
FALSE, // Set handle inheritance to FALSE
47+
CREATE_NO_WINDOW, // Creation flags
48+
NULL, // Use parent's environment block
49+
NULL, // Use parent's starting directory
50+
&startupInfo, // Pointer to STARTUPINFO structure
51+
&processInformation // Pointer to PROCESS_INFORMATION structure
52+
))
53+
{
54+
printf("CreateProcess failed: %d\n", GetLastError());
55+
THROW_HR(HRESULT_FROM_WIN32(GetLastError()));
56+
}
57+
58+
wil::unique_handle process{ processInformation.hProcess };
59+
wil::unique_handle thread{ processInformation.hThread };
60+
WaitForSingleObject(process.get(), (30 * 1000) /* 30 second timeout */ );
61+
62+
DWORD exitCode{};
63+
THROW_IF_WIN32_BOOL_FALSE(GetExitCodeProcess(process.get(), &exitCode));
64+
printf("Installer exit code: 0x%0X", HRESULT_FROM_WIN32(exitCode));
65+
return HRESULT_FROM_WIN32(exitCode);
66+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Windows.CppWinRT" version="2.0.211028.7" targetFramework="native" />
4+
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.211019.2" targetFramework="native" />
5+
</packages>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#include "pch.h"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#pragma once
5+
6+
#include <windows.h>
7+
#include <wil/result.h>
8+
#include <wil/cppwinrt.h>
9+
#include <wil/resource.h>
10+
#include <wil/token_helpers.h>
11+
#include <wil/win32_helpers.h>
12+
#include <wil/result_macros.h>
13+
14+
#include <string>
15+
#include <sstream>
16+
#include <filesystem>
17+
18+
#include <winrt/Windows.Foundation.h>
19+
#include <winrt/Windows.Foundation.Collections.h>
20+
#include <winrt/Windows.Management.Deployment.h>
21+
#include <winrt/Windows.System.h>

0 commit comments

Comments
 (0)