Skip to content

Commit

Permalink
FindProvisionedPackages sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Windows classic samples committed Nov 7, 2019
1 parent f483dd0 commit cc41cff
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Samples/DisplayCoreCustomCompositor/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
Windows.Devices.Display.Core Custom Compositor Sample
=======================================================
---
page_type: sample
languages:
- cpp
- cppwinrt
products:
- windows
description: "Create a compositor application that can present Direct3D content to a specialized monitor."
urlFragment: DisplayCoreCustomCompositor
---

# Windows.Devices.Display.Core Custom Compositor Sample

This sample demonstrates using the Windows.Devices.Display.Core APIs to create a compositor application that can present Direct3D content to a specialized monitor (such as a custom VR/AR headset).

Operating system requirements
-----------------------------
## Operating system requirements

Windows 10 1903
Windows 10 version 1903

Build the sample
----------------
## Build the sample

To build this sample, open the solution (.sln) file titled DisplayCoreCustomCompositor.sln from Visual Studio 2019 or later versions. Press F7 or go to Build-\>Build Solution from the top menu after the sample has loaded.

Run the sample
--------------
## Run the sample

Running this sample requires having a physical monitor that adheres to the [EDID Extension for HMDs and Specialized Displays](https://docs.microsoft.com/en-us/windows-hardware/drivers/display/specialized-monitors-edid-extension). Connect a compatible monitor before attempting to run the sample.

Expand Down
68 changes: 68 additions & 0 deletions Samples/PackageManagerFindProvisionedPackages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
page_type: sample
languages:
- csharp
products:
- windows
description: "Enumerate all app packages that are provisioned on the system."
urlFragment: PackageManagerFindProvisionedPackages
---

# Enumerate app packages

This sample shows how to enumerate all app packages that are provisioned on the machine.

Administrators and device manufacturers are able to provision an app package, using tools such as DISM or the Add-ProvisionedAppPackage cmdlet in Windows PowerShell. This will cause the app package to be installed for each user on their first (or next) login.

The sample uses [**PackageManager.FindProvisionedPackages()**](https://docs.microsoft.com/en-us/uwp/api/Windows.Management.Deployment.PackageManager) to find all installed packages for all users.

**Warning** This sample requires Microsoft Visual Studio 2019 Preview or a later version.

**Note** The Windows-classic-samples repo contains a variety of code samples that exercise the various programming models, platforms, features, and components available in Windows and/or Windows Server. This repo provides a Visual Studio solution (SLN) file for each sample, along with the source files, assets, resources, and metadata needed to compile and run the sample. For more info about the programming models, platforms, languages, and APIs demonstrated in these samples, check out the documentation on the [Windows Dev Center](https://dev.windows.com). This sample is provided as-is in order to indicate or demonstrate the functionality of the programming models and feature APIs for Windows and/or Windows Server. This sample was created for Windows 10 build 18917 using Visual Studio 2019, but in many cases it will run unaltered using later versions. Please provide feedback on this sample!

## Related technologies

[App packaging and deployment](http://msdn.microsoft.com/en-us/library/windows/desktop/hh446593)

## Operating system requirements

Client

Windows 10, build 18917 (or later)

Server

Windows Server 2012 R2

## Build the sample

### From the Command window

1. Open a Command Prompt window.

2. Go to the directory where you downloaded the FindProvisionedPackages sample.

3. Run the following command:

**msbuild FindProvisionedPackagesSample.sln**.

### From Visual Studio

1. Start Visual Studio and select **File** \> **Open** \> **Project/Solution**.

2. Go to the directory where you downloaded the FindProvisionedPackages sample and double-click its Microsoft Visual Studio Solution (.sln) file.

3. Press F7 or use **Build** \> **Build Solution**.

Run the sample
--------------

1. Open an elevated Command Prompt window.

2. Go to the directory that contains FindProvisionedPackagesSample.exe.

3. Run the following command:

**FindProvisionedPackagesSample**.


Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved

using System;
using System.Collections.Generic;
using System.Security.Principal;

class FindProvisionedPackagesSample
{
public static int Main(string[] args)
{
Console.WriteLine("Copyright (c) Microsoft Corporation. All rights reserved.");
Console.WriteLine("FindProvisionedPackages sample");
Console.WriteLine();

Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();

try
{
var packages = packageManager.FindProvisionedPackages();

if (packages.Count == 0)
{
Console.WriteLine("No packages were found.");
}
else
{
foreach (var package in packages)
{
DisplayPackageInfo(package);
Console.WriteLine();
}
}

}
catch (UnauthorizedAccessException)
{
Console.WriteLine("packageManager.FindProvisionedPackages() failed because access was denied. This program must be run from an elevated command prompt.");

return 1;
}
catch (Exception ex)
{
Console.WriteLine("packageManager.FindProvisionedPackages() failed, error message: {0}", ex.Message);
Console.WriteLine("Full Stacktrace: {0}", ex.ToString());

return 1;
}

return 0;
}

private static void DisplayPackageInfo(Windows.ApplicationModel.Package package)
{
Console.WriteLine("Name: {0}", package.Id.Name);

Console.WriteLine("FullName: {0}", package.Id.FullName);

Console.WriteLine("Version: {0}.{1}.{2}.{3}", package.Id.Version.Major, package.Id.Version.Minor,
package.Id.Version.Build, package.Id.Version.Revision);

Console.WriteLine("Publisher: {0}", package.Id.Publisher);

Console.WriteLine("PublisherId: {0}", package.Id.PublisherId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{82683839-7977-4813-B69C-E9E7F72B0207}</ProjectGuid>
<OutputType>Exe</OutputType>
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>FindProvisionedPackagesSample</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<MinimumVisualStudioVersion>12</MinimumVisualStudioVersion>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<RootNamespace>FindProvisionedPackagesSample</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Runtime" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Windows.ApplicationModel" />
<Reference Include="Windows.Management" />
</ItemGroup>
<ItemGroup>
<Compile Include="FindProvisionedPackagesSample.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="README.txt" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
<VisualStudioVersion>12.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
<VisualStudio AllowExistingFolder="true" />
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29311.281
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindProvisionedPackagesSample", "FindProvisionedPackagesSample.csproj", "{82683839-7977-4813-B69C-E9E7F72B0207}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{82683839-7977-4813-B69C-E9E7F72B0207}.Debug|x86.ActiveCfg = Debug|x86
{82683839-7977-4813-B69C-E9E7F72B0207}.Debug|x86.Build.0 = Debug|x86
{82683839-7977-4813-B69C-E9E7F72B0207}.Release|x86.ActiveCfg = Release|x86
{82683839-7977-4813-B69C-E9E7F72B0207}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B7817827-0661-46D2-92B9-823B3EE7492D}
EndGlobalSection
EndGlobal
41 changes: 41 additions & 0 deletions Samples/PackageManagerFindProvisionedPackages/cs/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Find Packages Sample
====================
This sample demonstrates how to use IPackageManager and IPackage APIs to
enumerate every package currently provisioned for all users on the machine.

NOTE: This sample must be run in an elevated command prompt.

Prerequisites
=============
This sample requires Windows 10, build 18917 or later.
This sample requires Visual Studio 2019 Preview or later.
This sample requires the Windows Runtime Software Development Kit.

Sample Language Implementations
===============================
C#

Files:
======
FindProvisionedPackagesSample.cs

To build the sample using the command prompt:
=============================================
1. Open the Command Prompt window and navigate to the directory.
2. Type msbuild FindProvisionedPackagesSample.sln.


To build the sample using Visual Studio 2019 Preview (preferred method):
================================================
1. Open File Explorer and navigate to the directory.
2. Double-click the icon for the .sln (solution) file to open the file in
Visual Studio.
3. In the Build menu, select Build Solution. The application will be
built in the default \Debug or \Release directory.


To run the sample:
==================
1. Open an elevated command prompt.
2. Navigate to the directory containing FindProvisionedPackagesSample.exe
2. Type FindProvisionedPackagesSample.exe at the command line.
3 changes: 3 additions & 0 deletions Samples/PackageManagerFindProvisionedPackages/cs/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

0 comments on commit cc41cff

Please sign in to comment.