透過使用 RemoteApp 虛擬機進行應用程式安裝

使用虛擬機服務目錄範本在 RemoteApp 虛擬機器上安裝並設定應用程式。

應用程式安裝腳本支援以下情境:

  • RemoteApp 應用程式安裝最常見的使用情境是部署可從 Azure 虛擬桌面 存取的遠端應用程式。
  • 安裝您的先備設備,如網路安全與監控代理。
  • 為合規性或應用程式設定進行指令碼組態變更。

Note

此範例部署僅供示範用途,並不代表網路、系統或應用程式管理的所有最佳實務。

先決條件

RemoteApp 範本支援腳本,以自動化安裝應用程式及設定虛擬機器的流程。 在開始使用 RemoteApp 應用程式安裝前,你需要確保具備:

  • 一個 社群、一個 隔離區、一個 工作負載,以及至少一個 工作負載資源群組,以及在該工作負載資源群組內建立資源的權限。
  • 啟用Advanced你的飛地維護模式,這樣你才能將 Private Link 資源加入你飛地管理的資源群組。
  • An 成品容器,位於儲存體帳戶內。
  • 社群端點連接至儲存體帳戶,且可以選擇性地連接至現有複本的 AzCopy.exe。
  • 一份 AzCopy.exe 的副本
    • 下載 AzCopy。
    • 把 AzCopy 安裝程式上傳到與應用程式資料夾同一層級的儲存帳號。
    • 檔案結構:
          - storage account
              - artifacts container
                  - app folder
                  - azcopy.exe 
      
      螢幕擷取畫面顯示儲存體容器的組織結構:同一容器中有多個應用程式資料夾,且使用同一份 AzCopy.exe。
  • 先前建立的社群端點與隔離區子網之間的隔離區連線。

Note

如果儲存體帳戶位於不同的 enclave 中,請在包含該儲存體帳戶的 enclave 中建立一個 enclave 端點。 接著在該儲存帳號隔離區和你安裝應用程式的隔離區之間建立一個 enclave 連線 。

已部署的 Azure 資源

  • RemoteApp 範例虛擬機
    • 磁碟
    • Windows 虛擬機器
    • Windows 虛擬機擴充套件

已部署的軟體

  • Windows 作業系統
  • 你選擇的應用

部署範本

準備申請文件

  1. 將應用程式資料夾加入儲存帳號的容器。 顯示在同一隔離區內安裝方法的示意圖。 顯示在包含儲存體帳戶的隔離區之外安裝方法的示意圖。
    • 檔案結構:
          - artifacts container
              - app folder
                  - app installer
                  - main script to install app
                  - (optional) additional scripts
                  - (optional) azcopy.exe
      
  2. 下載你需要的應用程式安裝程式。 在這個範例中,下載 Visual Studio Code 並將安裝程式上傳到儲存帳號的應用程式資料夾。
  3. 將與您新增至儲存體帳戶應用程式資料夾中的 Visual Studio Code 版本相容的 main.ps1 應用程式安裝程式指令碼上傳:
        # Main PowerShell script that installs the application
    
        Start-Process 'C:\vscode\VSCodeSetup-x64-<version>.exe' -ArgumentList '/VERYSILENT /MERGETASKS=!runcode'
    

設定範本

  1. 在工作負載總覽頁面,選擇 +Add an Azure Service。

工作負載總覽頁面的截圖。

  1. 針對Service,選取Virtual Machine。

截圖顯示從服務目錄列表中選擇的虛擬機。

  1. 確認資源群組的選擇,然後選擇 「下一步」。

  2. 基礎標籤:

    • 對於 Virtual Machine name,輸入虛擬機名稱。
    • 對於 管理員使用者名稱 和 管理員密碼,輸入你用來登入虛擬機器的使用者名稱和密碼。
  3. 應用程式分頁:

    • 針對應用程式資料夾 URI,請輸入容器的 URI。 在容器內選擇一個產物,複製它的 URI,然後移除 URI 中資料夾名稱之後的所有內容。 這是本次部署中使用的應用程式資料夾 URI 截圖。

      原始 URI 已修正 URI
      https://<storage-account>.blob.core.windows.net//<container-name><folder-name>/<script>.ps1 https://<storage-account>.blob.core.windows.net/<container-name>/<folder-name>
    • Example:

      • storageaccountexample.blob.core.windows.net/artifacts/vscode
    • 對於 主腳本,輸入安裝應用程式的腳本名稱(例如:main.ps1)。

    虛擬機部署期間應用程式分頁的截圖。

私人貨櫃:

  1. 針對私人容器中的應用程式資料夾,請選取true ,以授與虛擬機器身分識別容器層級的Storage Blob Data Reader存取權。

  2. 對於儲存體容器資源識別碼,將這三個部分組合起來:<storage-account-resource-id> + /blobServices/default/containers/ + <container-name>

    • 如要取得儲存體容器資源識別碼,請在儲存體帳戶中選取 概覽,選取最右側角落的JSON 檢視,然後複製儲存體帳戶資源識別碼。

    本次部署使用的帳號資源 ID 截圖。

    • 對於容器名稱,複製存放這些文物的私人容器名稱。
    • 範例儲存容器資源 ID: /subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourceGroups/resource-group-example/providers/Microsoft.Storage/storageAccounts/storage-account-example/blobServices/default/containers/container-name
  3. 如果顯示 AzCopy File URI參數,請輸入容器中azcopy.exe的 URI。

    • 選擇檔案,並複製其網址:

    顯示儲存容器組織結構及 azcopy.exe 檔案的截圖。

    截圖顯示 azcopy.exe 檔案的 URI。

範例私有容器參數:

顯示 App 索引標籤參數已填寫完成的螢幕擷取畫面。

  1. 選取 [檢閱並建立]。 如果驗證通過,請選擇 「建立」。
  2. 資源部署完成後,請透過連接應用程式虛擬機檢查應用程式是否安裝在虛擬機上。 連接應用程式虛擬機

安裝 WinGet 及其他應用程式

資料夾結構:

- artifacts container
    - WinGet app folder ('winget')
        - WinGet installer ('Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle')
        - Windows UI Library ('Microsoft.UI.Xaml.2.8.x64.appx')
        - main script to schedule install ('main.ps1')
        - script to install and schedule reboot ('install_winget.ps1')
        - script to restart the virtual machine ('restart.ps1')

螢幕擷取畫面顯示將 winget 安裝到 RemoteApp 上所需的項目,以便之後使用 winget 安裝及管理其他應用程式。

  1. 下載安裝程式並上傳到 storage container 裡的 winget 資料夾
  2. 建立並上傳腳本
    1. main.ps1
      # This script creates and runs a scheduled task to install the appx package and msix bundle with elevated privileges
      
      $installScriptPath = "C:\winget\install_winget.ps1"
      
      # Create a scheduled task action to run the installation script with elevated permissions
      $taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy Bypass -File $installScriptPath"
      
      # Set the task to start 30 seconds from now
      $taskTrigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(30)
      $taskPrincipal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
      
      # Register the scheduled task
      Register-ScheduledTask -TaskName "InstallWinget" -Action $taskAction -Trigger $taskTrigger -Principal $taskPrincipal
      
    2. install_winget.ps1
      Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
      
      Start-Process -FilePath "DISM.exe" -ArgumentList "/Online /Add-ProvisionedAppxPackage /PackagePath:C:\winget\Microsoft.UI.Xaml.2.8.x64.appx /SkipLicense" -NoNewWindow -Wait
      Start-Process -FilePath "DISM.exe" -ArgumentList "/Online /Add-ProvisionedAppxPackage /PackagePath:C:\winget\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle /SkipLicense" -NoNewWindow -Wait
      
      $wingetDir = 'C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.23.1791.0_x64__8wekyb3d8bbwe'
      $currentPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
      [System.Environment]::SetEnvironmentVariable("Path", "$currentPath;$wingetDir", [System.EnvironmentVariableTarget]::Machine)
      
      # Schedule the restart script
      $rebootScriptPath = "C:\winget\restart.ps1"
      $taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy Bypass -File $rebootScriptPath"
      
      # Set the task to start 30 seconds from now
      $taskTrigger = New-ScheduledTaskTrigger -Once -At ((Get-Date).AddSeconds(30))
      $taskPrincipal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
      
      # Register the scheduled task
      Register-ScheduledTask -TaskName "Reboot" -Action $taskAction -Trigger $taskTrigger -Principal $taskPrincipal
      
    3. restart.ps1
      Restart-Computer -Force
      
  3. 繼續設定範本。