

# Persist Environment Variables in Amazon WorkSpaces Applications
<a name="customize-fleets-persist-environment-variables"></a>

Environment variables enable you to dynamically pass settings across applications. For example, many engineering applications rely on environment variables to specify the IP address or host name of a license server to locate and check out a license from that server. 

Follow the steps in these procedures to make environment variables available across your fleet instances. 

**Note**  
The following instructions apply to Windows fleets only. 

**Topics**
+ [Change System Environment Variables](customize-fleets-system-environment-variables.md)
+ [Change User Environment Variables](customize-fleets-user-environment-variables.md)
+ [Create an Environment Variable That is Limited in Scope](customize-fleets-environment-variable-limited-scope.md)

**Note**  
If you are using Active Directory and Group Policy with WorkSpaces Applications, keep in mind that streaming instances must be joined to an Active Directory domain to use Group Policy for environment variables. For information about how to configure the Group Policy **Environment Variable** preference item, see [Configure an Environment Variable Item](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc772047(v=ws.11)) in the Microsoft documentation.

# Change System Environment Variables
<a name="customize-fleets-system-environment-variables"></a>

Follow these steps to change system environment variables across your fleet instances. 

**To change system environment variables on an image builder**

This procedure applies only to system environment variables, not user environment variables. To change user environment variables that persist across your fleet instances, perform the steps in the next procedure.

1. Connect to the image builder on which to change system environment variables and sign in with an account that has local administrator permissions. To do so, do either of the following: 
   + [Use the WorkSpaces Applications console](managing-image-builders-connect-console.md) (for web connections only)
   + [Create a streaming URL](managing-image-builders-connect-streaming-URL.md) (for web or WorkSpaces Applications client connections)
**Note**  
If the image builder that you want to connect to is joined to an Active Directory domain and your organization requires smart card sign in, you must create a streaming URL and use the WorkSpaces Applications client for the connection. For information about smart card sign in, see [Smart Cards](feature-support-USB-devices-qualified.md#feature-support-USB-devices-qualified-smart-cards).

1. Choose the Windows **Start** button, open the context (right-click) menu for **Computer**, and then choose **Properties**.

1. In the navigation pane, choose **Advanced system settings**. 

1. In **System variables**, change the environment variables that you want to persist across your fleet instances, and then choose** OK**.

1. On the image builder desktop, open Image Assistant.

1. Follow the necessary steps in Image Assistant to finish creating your image. For more information, see [Tutorial: Create a Custom WorkSpaces Applications Image by Using the WorkSpaces Applications Console](tutorial-image-builder.md).

   The changes to the system environment variables persist across your fleet instances and are available to streaming sessions launched from those instances. 
**Note**  
Setting AWS CLI credentials as system environment variables might prevent WorkSpaces Applications from creating the image.

# Change User Environment Variables
<a name="customize-fleets-user-environment-variables"></a>

Follow these steps to change user environment variables across your fleet instances. 

**To change user environment variables**

1. Connect to the image builder on which to change system environment variables and sign in as a **Template User**. To do so, do either of the following: 
   + [Use the WorkSpaces Applications console](managing-image-builders-connect-console.md) (for web connections only)
   + [Create a streaming URL](managing-image-builders-connect-streaming-URL.md) (for web or WorkSpaces Applications client connections)
**Note**  
If the image builder that you want to connect to is joined to an Active Directory domain and your organization requires smart card sign in, you must create a streaming URL and use the WorkSpaces Applications client for the connection. For information about smart card sign in, see [Smart Cards](feature-support-USB-devices-qualified.md#feature-support-USB-devices-qualified-smart-cards).

   **Template User** lets you create default application and Windows settings for your users. For more information, see "Creating Default Application and Windows Settings for Your WorkSpaces Applications Users" in [Default Application and Windows Settings and Application Launch Performance in Amazon WorkSpaces Applications](customizing-appstream-images.md).

1. On the image builder, choose the Windows **Start** button, **Control Panel**, **User Accounts**. 

1. Choose **User Accounts** again. In the left navigation pane, choose **Change my environment variables.**

1. Under **User environment variables** for **DefaultProfileUser**, set or create the user environment variables as needed, then choose **OK**.

1. This disconnects your current session and opens the login menu. Log in to the image builder by doing either of the following:
   + If your image builder is not joined to an Active Directory domain, on the **Local User** tab, choose **Administrator**.
   + If your image builder is joined to an Active Directory domain, choose the **Directory User** tab, and log in as a domain user who has local administrator permissions on the image builder.

1. On the image builder desktop, open Image Assistant.

1. Follow the necessary steps in Image Assistant to finish creating your image. For more information, see [Tutorial: Create a Custom WorkSpaces Applications Image by Using the WorkSpaces Applications Console](tutorial-image-builder.md).

# Create an Environment Variable That is Limited in Scope
<a name="customize-fleets-environment-variable-limited-scope"></a>

Follow these steps to create an environment variable that is limited in scope to the processes that are spawned off the script. This approach is useful when you need to use the same environment variable name with different values for different applications. For example, if you have two different applications that use the environment variable "LIC\$1SERVER", but each application has a different value for "LIC\$1SERVER".

**To create an environment variable that is limited in scope**

1. Connect to the image builder on which to create an environment variable that is limited in scope and sign in with an account that has local administrator permissions. To do so, do either of the following: 
   + [Use the WorkSpaces Applications console](managing-image-builders-connect-console.md) (for web connections only)
   + [Create a streaming URL](managing-image-builders-connect-streaming-URL.md) (for web or WorkSpaces Applications client connections)
**Note**  
If the image builder that you want to connect to is joined to an Active Directory domain and your organization requires smart card sign in, you must create a streaming URL and use the WorkSpaces Applications client for the connection. For information about smart card sign in, see [Smart Cards](feature-support-USB-devices-qualified.md#feature-support-USB-devices-qualified-smart-cards).

1. Create a child folder of C:\$1 drive for the script (for example, C:\$1Scripts).

1. Open Notepad to create the new script, and enter the following lines:

   `set `*variable*=*value*

   `start " " "C:\path\to\application.exe"` 

   Where:

   *variable* is the variable name to be used

   *value* is the value for the given variable name
**Note**  
If the application path includes spaces, the entire string must be encapsulated within quotation marks. For example:   
`start " " "C:\Program Files\application.exe"`

1. Choose** File**, **Save**. Name the file and save it with the .bat extension to C:\$1Scripts. For example, name the file LaunchApp.bat.

1. If needed, repeat steps 4 and 5 to create a script for each additional application that requires its own environment variable and values. 

1. On the image builder desktop, start Image Assistant.

1. Choose **Add App**, navigate to C:\$1Scripts, and select one of the scripts that you created in step 5. Choose **Open**.

1. In the **App Launch Settings** dialog box, keep or change the settings as needed. When you're done, choose **Save**.

1. If you created multiple scripts, repeat steps 8 and 9 for each script.

1. Follow the necessary steps in Image Assistant to finish creating your image. For more information, see [Tutorial: Create a Custom WorkSpaces Applications Image by Using the WorkSpaces Applications Console](tutorial-image-builder.md).

   The environment variable and specific value are now available for processes that are run from the script. Other processes cannot access this variable and value. 