Video Screencast Help
Search Video Help Close Back
to help
New in the Rewards Catalog: Vouchers for "Symantec Technical Specialist" and "Symantec Certified Specialist" exams.

Using Inventory to Restore Environment Variables After Imaging

Updated: 07 Feb 2008
ianatkin's picture
+1 1 Vote
Login to vote

Many organizations can configure local environment variables on their systems that can detail useful information such as asset details, location or even printer configuration.

When imaging computers to fix issues, this information has to be uploaded to the server, so it can be restored as a post-imaging task.

The most obvious way is to run a script on the client which,

  1. Maps a drive to the Deployment Server
  2. Exports the selected environment variables as a batch file env-%ID%.bat in \Express\temp

Using this approach requires,

  1. Your Clients and DS to be in the same Domain, or a common credential to be shared across your PC estate
  2. Windows Networking to be reliable... ;-)

The Workaround

A workaround which we have found to be quite robust is to run a job before imaging a client computer which exports the required environment variables to fake Add/Remove program entries. These can then be picked up by the AClient inventory, which in turn can be used to create a batch file to re-import your environment variables after imaging.

For Example

To explain this approach, consider machines which have their some asset information set as an environment variable called Asset_No. To upload the environment variables we need to create a job called "Upload Environment Variables" consisting of three tasks.

Task 1: Run script on client move Environment Variables to inventory data

This first task exports the environment variable to a registry file, which is then imported using regedit in silent mode. This is long winded, but this will work on both Windows 2000 and Windows XP systems,

REM Copy Environment Variables to Inventory data
Echo Windows Registry Editor Version 5.00 > %temp%\env.reg
Echo. >> %temp%\env.reg

Echo[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\
CurrentVersion\Uninstall\ENV1] >> %temp%\env.reg
Echo "DisplayName"="%Asset_No%" >>%temp%\env.reg

regedit /s %temp%\env.reg

REM For Windows XP systems, you can use the reg command
REM -much simpler....
REM HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\
REM Uninstall\ENV1 /v "DisplayName" /t REG_SZ  /d %Asset_No% /f

Task 2: Get Inventory

Here we simply inset the standard DS task of 'Get Inventory'

Task 3: Convert Inventory data to batch file

Now we have our environment data tucked away as an application named ENV1, we need to get this data out into a batch file ready for running as a post image task.

This can be done through a very simple script to be executed on the deployment server.

REM Extract Environments variables from inventory and dump to batch

echo setx Asset_No %#*"select description from dbo.application where (computer_id like %ID% AND [name] like 'ENV1')"% > .\temp\%env-%ID%.bat

Note that setting environment variables at the system level requires the use of the Microsoft SETX utility, available in the Windows Resource kits. Using the SET command by itself can only configure environment variables with the life of the shell they are created in.

You can tackle the restoration in a variety of ways. In your restore image job, I typically add three post image tasks to make it clear what we are doing,

Task 1: Copy Setx

This task should copy SETX to some folder such as %temp%\SetX

Task 2: Copy Environment Batch File

This task should copy .\Temp\env-%ID%.bat to the %temp%\SetX folder on the client.

Task 2: Execute env-%ID%.bat

This task should be a script, which moves into the %temp%\SetX folder on the client. This is to ensure that SETX.EXE is in the path. The script should then execute the env-%ID%.bat file on the client.

I hope this is of some use to others out there. Good Luck!