Automating the Launch of a Windows Virtual Desktop / AVD Resource via Microsoft Remote Desktop (MSRDC)

 

Purpose

This article describes how to automatically start a WVD/AVD resource using the Microsoft Remote Desktop client (MSRDC), under the correct user context, optionally with a “friendly name” for clearer identification.

Functional Steps

  1. Determine the MSRDC installation path
    The code will attempt to read the standard installation path from the registry.
    If that fails, it will fall back to a default path.
  2. Read the ms-rd protocol value from the Windows registry
    Look under:

    HKEY_CLASSES_ROOT\ms-rd\shell\open\command
     
  3. The default value contains the MSRDC command and path. Note: The ms-rd: URI scheme is only supported with the Windows Desktop client. Microsoft Learn
    The code strips "%1" from the command string and uses Path.GetDirectoryName(...) to get the installation directory.
  4. Fallback location if registry read fails

    %LocalAppData%\Apps\Remote Desktop

    e.g., C:\Users\<user>\AppData\Local\Apps\Remote Desktop
     
  5. Build the launch arguments for MSRDC

    "<rdpFilePath>" /u:<userName> /l:<launchSource> /p:<currentProcessId> [/n:"<friendlyName>"]
    rdpFilePath: full path to the downloaded RDP profile
    userName: the user for the session
    launchSource: integer code indicating source of the launch (e.g., 2)
    p:<currentProcessId>: the current process ID is filled automatically
    /n:"<friendlyName>": optional friendly name, only included if provided
     
  6. Start MSRDC
    Execute msrdc.exe with the constructed arguments. MSRDC launches the session using the supplied RDP profile and user context.

Parameters

  • rdpFilePath: Full file path to the downloaded RDP profile.
  • userName: Username to launch the session with.
  • friendlyName: (Optional) A human-readable name shown in MSRDC UI or title.
  • launchSource: An integer that indicates the origin of the launch (for internal tracking).
  • currentProcessId: The process ID of the launching process, inserted automatically.

Expected Locations & Paths

  • RDP files (download):

    %AppData%\LoadGen\WVD\<guid>

    Example: C:\Users\<user>\AppData\Roaming\LoadGen\WVD\4e5f...
  • MSRDC installation path (via registry):
    Registry key:

    HKEY_CLASSES_ROOT\ms-rd\shell\open\command

    The default value contains the command path; code extracts the directory.
  • MSRDC installation path (fallback):

    %LocalAppData%\Apps\Remote Desktop

    Example: C:\Users\<user>\AppData\Local\Apps\Remote Desktop

Logging & error handling

  • During path construction and registry reads, logging is performed.
  • If an error occurs (e.g., MSRDC path cannot be determined or process start fails), an error is logged and the result False is returned.
  • If friendlyName is not supplied, the /n: parameter is omitted, and MSRDC launches without a custom name.

System Requirements & conditions

  • Windows system with MSRDC installed and properly registered (or available at fallback location).
  • Access to the RDP profile file on disk.
  • Adequate user permissions and network connectivity to establish the session.

Visible result

  • The Microsoft Remote Desktop (MSRDC) client launches.
  • The session starts using the specified user context.
  • If friendlyName is provided, the custom name appears in the MSRDC UI or window title.
Was this article helpful?
1 out of 1 found this helpful