Skip to content

Policy Recipes: File Associations

Task-oriented file association recipes you can copy/paste. These recipes use the unified model with fileTypes, apps[].capabilities, and fileAssociations.

What You'll Learn

  • How to define fileTypes and reuse them across apps and associations
  • How to keep apps hidden from Applications while still available via Open With
  • How to shape default open/preview/print behavior for different extensions

File Association Recipes (Unified Model)

These recipes use the unified model: fileTypes + apps[].capabilities + fileAssociations. They replace the previous fileHandlers/fileRouting model.

PDFs With Built-In Preview and Hidden Chrome for Open With

Keep Chrome hidden from Applications but available to open PDFs via Open With. Default action is preview in-app.

json
{
  "fileTypes": [
    { "id": "pdf", "displayName": "PDF", "match": { "extensions": ["pdf"] }, "defaultPreviewProvider": "builtInPdf" }
  ],
  "apps": [
    {
      "id": "google-chrome",
      "displayName": "Google Chrome",
      "enabled": true,
      "priority": 150,
      "visibility": "hidden",
      "matchAll": [ { "type": "targetPath", "pattern": ".*chrome\\.exe$", "patternType": "regex" } ],
      "action": "allow",
      "capabilities": [
        { "fileTypeRef": "pdf", "verbs": { "open": { "arguments": "\"%1\"" } } }
      ]
    }
  ],
  "fileAssociations": [
    {
      "id": "pdf-routing",
      "displayName": "PDF",
      "enabled": true,
      "priority": 250,
      "fileTypeRef": "pdf",
      "actions": [
        { "verb": "preview", "displayName": "Preview", "provider": "builtInPdf", "default": true },
        { "verb": "open", "displayName": "Open", "appRef": "google-chrome", "showInOpenWith": true }
      ]
    }
  ]
}

Validate:

  • Chrome is not visible in Applications (visibility: "hidden").
  • Opening a .pdf uses built-in preview by default.
  • Open With lists Chrome; selecting it opens the file in Chrome.

Word Docs With Split docx vs doc and Hidden App

Default to standard open for docx; use compatibility mode for doc. Word remains hidden from Applications.

json
{
  "fileTypes": [
    { "id": "word-docs", "displayName": "Word Documents", "match": { "extensions": ["doc", "docx"] } }
  ],
  "apps": [
    {
      "id": "ms-word",
      "displayName": "Microsoft Word",
      "enabled": true,
      "priority": 200,
      "visibility": "hidden",
      "matchAll": [ { "type": "targetPath", "pattern": ".*WINWORD\\.EXE$", "patternType": "regex" } ],
      "action": "allow",
      "capabilities": [
        {
          "fileTypeRef": "word-docs",
          "verbs": {
            "open":  { "arguments": "\"%1\"" },
            "edit":  { "arguments": "/e \"%1\"" },
            "print": { "arguments": "/p \"%1\"" }
          }
        }
      ]
    }
  ],
  "fileAssociations": [
    {
      "id": "word-docs-routing",
      "displayName": "Word docs",
      "enabled": true,
      "priority": 300,
      "fileTypeRef": "word-docs",
      "actions": [
        { "verb": "open", "displayName": "Open", "appRef": "ms-word", "match": { "extensions": ["docx"] }, "default": true, "showInOpenWith": true },
        { "verb": "open", "displayName": "Open (Compatibility Mode)", "appRef": "ms-word", "match": { "extensions": ["doc"] }, "showInOpenWith": true },
        { "verb": "print", "displayName": "Print", "appRef": "ms-word", "default": true }
      ]
    }
  ]
}

Validate:

  • Opening a .docx uses standard open and is the default action.
  • Opening a .doc uses compatibility mode (invokes open verb with different match).
  • Open With shows both options where appropriate.
  • Print action routes to Word's print capability with /p arguments.

Image Previews (Built-In Only)

Enable built-in image preview as the default action, without associating an external app.

json
{
  "fileTypes": [
    { "id": "images", "displayName": "Images", "match": { "extensions": ["png", "jpg", "jpeg", "gif"] }, "defaultPreviewProvider": "builtInImage" }
  ],
  "fileAssociations": [
    {
      "id": "images-routing",
      "displayName": "Images",
      "enabled": true,
      "priority": 200,
      "fileTypeRef": "images",
      "actions": [
        { "verb": "preview", "displayName": "Preview", "provider": "builtInImage", "default": true }
      ]
    }
  ]
}

Validate:

  • Selecting an image in the Files tab or other UI previews inline.
  • No external app is required for the default preview behavior.

Disable Print for PDFs (Omit Print Actions)

Remove the Print action for PDFs entirely by omitting print actions.

json
{
  "fileTypes": [
    { "id": "pdf", "displayName": "PDF", "match": { "extensions": ["pdf"] }, "defaultPreviewProvider": "builtInPdf" }
  ],
  "fileAssociations": [
    {
      "id": "pdf-no-print",
      "displayName": "PDF (no printing)",
      "enabled": true,
      "priority": 250,
      "fileTypeRef": "pdf",
      "actions": [
        { "verb": "preview", "displayName": "Preview", "provider": "builtInPdf", "default": true }
      ]
    }
  ]
}

Validate:

  • Print is not offered for .pdf files in the UI.
  • Preview continues to work using the built-in provider.

Developer Source Files → Hidden Editor via Associations

Default text-like and source extensions to a hidden editor (for example, VS Code), available through file associations.

json
{
  "fileTypes": [
    {
      "id": "source-files",
      "displayName": "Source files",
      "match": { "extensions": ["txt","md","json","yml","yaml","xml","ini","cfg","log","js","ts","jsx","tsx","css","scss","less","py","rb","go","rs","java","c","cpp","h","hpp","cs"] }
    }
  ],
  "apps": [
    {
      "id": "code-editor",
      "displayName": "Code Editor",
      "enabled": true,
      "priority": 190,
      "visibility": "hidden",
      "matchAll": [ { "type": "targetPath", "pattern": ".*(Code|notepad\\+\\+|sublime_text)\\.exe$", "patternType": "regex" } ],
      "action": "allow",
      "capabilities": [
        { "fileTypeRef": "source-files", "verbs": { "open": { "arguments": "\"%1\"" } } }
      ]
    }
  ],
  "fileAssociations": [
    {
      "id": "source-files-routing",
      "displayName": "Source files",
      "enabled": true,
      "priority": 280,
      "fileTypeRef": "source-files",
      "actions": [
        { "verb": "open", "displayName": "Open", "appRef": "code-editor", "default": true, "showInOpenWith": true }
      ]
    }
  ]
}

Validate:

  • Double-clicking a matching source file opens in the hidden editor.
  • Open With lists the Code Editor entry.
  • The editor does not appear in Applications if visibility is hidden.

RDP and VNC Clients + Associations

Allow mstsc and VNC viewers and wire their file types via associations.

json
{
  "fileTypes": [
    { "id": "rdp", "displayName": "RDP", "match": { "extensions": ["rdp"] } },
    { "id": "vnc", "displayName": "VNC", "match": { "extensions": ["vnc"] } }
  ],
  "apps": [
    {
      "id": "rdp-client",
      "displayName": "Remote Desktop Connection",
      "enabled": true,
      "priority": 160,
      "matchAll": [ { "type": "targetPath", "pattern": ".*mstsc\\.exe$", "patternType": "regex" } ],
      "action": "allow",
      "capabilities": [ { "fileTypeRef": "rdp", "verbs": { "open": { "arguments": "\"%1\"" } } } ]
    },
    {
      "id": "vnc-viewer",
      "displayName": "VNC Viewer",
      "enabled": true,
      "priority": 160,
      "matchAll": [ { "type": "targetPath", "pattern": ".*vncviewer.*\\.exe$", "patternType": "regex" } ],
      "action": "allow",
      "capabilities": [ { "fileTypeRef": "vnc", "verbs": { "open": { "arguments": "\"%1\"" } } } ]
    }
  ],
  "fileAssociations": [
    {
      "id": "rdp-routing",
      "displayName": "RDP",
      "enabled": true,
      "priority": 260,
      "fileTypeRef": "rdp",
      "actions": [ { "verb": "open", "displayName": "Open", "appRef": "rdp-client", "default": true, "showInOpenWith": true } ]
    },
    {
      "id": "vnc-routing",
      "displayName": "VNC",
      "enabled": true,
      "priority": 260,
      "fileTypeRef": "vnc",
      "actions": [ { "verb": "open", "displayName": "Open", "appRef": "vnc-viewer", "default": true, "showInOpenWith": true } ]
    }
  ]
}

Validate:

  • .rdp files open in the RDP client; .vnc files open in the VNC client.
  • Both applications appear in Open With for their respective file types.

ZIP Extraction With Custom Extract Verb

Use Windows built-in tar.exe to extract ZIP files via a custom extract verb. Demonstrates variable substitution with %~dpn1 for destination paths.

json
{
  "fileTypes": [
    {
      "id": "zip-archive",
      "displayName": "Compressed (zipped) Folder",
      "match": { "extensions": ["zip"] }
    }
  ],
  "apps": [
    {
      "id": "system-tar",
      "displayName": "System Tar",
      "targetPath": "%SYSTEMROOT%\\System32\\cmd.exe",
      "enabled": true,
      "priority": 60,
      "visibility": "hidden",
      "action": "allow",
      "capabilities": [
        {
          "fileTypeRef": "zip-archive",
          "verbs": {
            "extract": { "arguments": "/c mkdir \"%~dpn1\" & tar -xf \"%1\" -k -C \"%~dpn1\"" }
          }
        }
      ]
    }
  ],
  "fileAssociations": [
    {
      "id": "zip-extraction-routing",
      "displayName": "Extract ZIP archives",
      "enabled": true,
      "priority": 100,
      "fileTypeRef": "zip-archive",
      "actions": [
        { "verb": "extract", "displayName": "Extract", "appRef": "system-tar", "default": true }
      ]
    }
  ]
}

Validate:

  • Right-clicking a .zip file shows Extract in the context menu.
  • Extraction creates a folder with the archive name and extracts contents into it.
  • Uses system tar utility via targetPath without requiring discovery.
  • Variable %~dpn1 resolves to the derived destination path (e.g., C:\Downloads\MyArchive\).

See also: