-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Windows classic samples
committed
Nov 7, 2019
1 parent
f483dd0
commit cc41cff
Showing
7 changed files
with
292 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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**. | ||
|
||
|
70 changes: 70 additions & 0 deletions
70
Samples/PackageManagerFindProvisionedPackages/cs/FindProvisionedPackagesSample.cs
This file contains 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
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); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
Samples/PackageManagerFindProvisionedPackages/cs/FindProvisionedPackagesSample.csproj
This file contains 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
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)' < '12.0' "> | ||
<VisualStudioVersion>12.0</VisualStudioVersion> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" /> | ||
<ProjectExtensions> | ||
<VisualStudio AllowExistingFolder="true" /> | ||
</ProjectExtensions> | ||
</Project> |
25 changes: 25 additions & 0 deletions
25
Samples/PackageManagerFindProvisionedPackages/cs/FindProvisionedPackagesSample.sln
This file contains 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
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
41
Samples/PackageManagerFindProvisionedPackages/cs/README.txt
This file contains 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
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. |
This file contains 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
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> |