Access the WinRT API from a desktop application

  • Gérald Barré

When looking at MSDN help for a Windows 8 API class, such as PasswordVault, it is indicated that this class can be used from a Windows Store application or a Desktop application (Console, WinForms or WPF):

In the case of a Windows Store application, you have no references to add. Just add the specified using. For a desktop application, it's a little more complicated:

Here is the procedure for using the API from a desktop application:

  1. Edit the csproj file and add <TargetPlatformVersion>8.0</TargetPlatformVersion>

    csproj (MSBuild project file)
    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="">
      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
      <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  2. Add a reference to Windows

  3. Add a reference to System.Runtime (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.dll)

  4. Use the API

You can now access a WinRT API class from your desktop application:

var vault = new Windows.Security.Credentials.PasswordVault();
var credentials = vault.RetrieveAll();
foreach (PasswordCredential credential in credentials)
    Console.WriteLine("{0} {1}", credential.Resource, credential.UserName);

There you go.

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub