Skip to content

Shortcut Resource

Synopsis

Manages Windows shortcut (.lnk) files using COM interop with the Windows Shell.

Type

OpenDsc.Windows/Shortcut

Capabilities

  • Get
  • Set
  • Delete

Properties

path

The full path to the .lnk file.

Type: string
Required: Yes
Access: Read/Write
Default value: None

targetPath

The target path the shortcut points to.

Type: string
Required: No
Access: Read/Write
Default value: None

arguments

Command-line arguments for the target.

Type: string
Required: No
Access: Read/Write
Default value: None

workingDirectory

The working directory for the target.

Type: string
Required: No
Access: Read/Write
Default value: None

description

A description for the shortcut.

Type: string
Required: No
Access: Read/Write
Default value: None

iconLocation

The icon file path and index.

Type: string
Required: No
Access: Read/Write
Default value: None

hotkey

The hotkey combination for the shortcut.

Type: string
Required: No
Access: Read/Write
Default value: None

windowStyle

Window style. Accepts Normal, Minimized, or Maximized.

Type: enum
Required: No
Access: Read/Write
Default value: None

_exist

Whether the shortcut should exist.

Type: bool
Required: No
Access: Read/Write
Default value: true

Examples

Example 1 — Create a desktop shortcut

$resourceInput = @'
path: C:\Users\Public\Desktop\Notepad.lnk
targetPath: C:\Windows\notepad.exe
description: Open Notepad
'@

dsc resource set -r OpenDsc.Windows/Shortcut --input $resourceInput
resource_input=$(cat <<'EOF'
path: C:\Users\Public\Desktop\Notepad.lnk
targetPath: C:\Windows\notepad.exe
description: Open Notepad
EOF
)

dsc resource set -r OpenDsc.Windows/Shortcut --input "$resource_input"

Example 2 — Configuration document

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
  - name: Notepad shortcut on desktop
    type: OpenDsc.Windows/Shortcut
    properties:
      path: C:\Users\Public\Desktop\Notepad.lnk
      targetPath: C:\Windows\notepad.exe
      description: Open Notepad

Exit codes

Code Description
0 Success
1 Error
2 Invalid JSON
3 Failed to generate schema
4 Directory not found