Horizon Cloud – Run Once Script

Introduction

Run Once is an optional component while creating an assignment and it has many uses
In this article , I would like to discuss about how this works for dedicated & floating assignments in Horizon Cloud

Most of the admins are using run once to update the group policies as soon as domain join completes so that all organisation level polices will get updated with VDI creation itself , not only for group policy updates – it can be used to run one time scripts to set policies , registry keys , create folders & etc

How to create a run once script – Example

  • As a best practice , create a folder for run once scripts in the base image – Ex: C:\runonce
  • Open a notepad or an equivalent editor to create the script
  • At the beginning in the first line type as – @echo off 
  • now enter the command that you would like to run at start up – Ex: “cmd.exe /k “gpupdate /force”
  • Don’t forget to add shutdown /r /t 0 at the bottom of script
  • End the last line by typing – exit
  • Save the file as <name>.bat – Ex: runonce.bat
  • copy the path of the runonce script to input into assignment creation wizard – Ex: C:\runonce\runonce.bat

Why “shutdown /r /t 0 ” is mandatory at the end

  • The runonce script always runs only after the sysprep
  • Once after the sysprep , at the time of domain join – horizon agent in the VM get the path of runonce specified in the assignment
  • Horizon agent sets the runonce path in the windows registry and restarts the vm to complete the domain join
  • After the restart , system logs in to operating system with local admin credentials and runs this script
  • If we won’t specify the restart command after the commands run the vm not usable for user logins till manually restarted

How the Dedicated assignment flow works

Based on my testing , the flow works something like below

      - VM clone success
      - wait till machine boots up and sysprep completes
      - Agent will rename the computer with desired one & domain join 
      - Add runonce script path to registry - set the autologon 
      - reboot the machine
      - Auto logon with local admin credentials
      - execute Runonce script & restart

How the floating assignment flow works

Based on my testing , the flow works something like below

      - VM clone success
      - wait till machine boots up and sysprep completes
      - Agent will rename the computer with desired one & domain join
      - Add runonce script path to registry - set the autologon 
      - reboot the machine
      - Snapshot
      - Auto logon with local admin credentials
      - execute Runonce script & restart

With the DAAS if you see any inconsistencies with floating desktops flow- please follow below VMware KB for best practices

https://kb.vmware.com/s/article/87668

Scroll to Top