Handling HKCU registry keys when packaging

Overview

Many programs use HKCU registry keys to store settings for specific users. Unfortunately, these keys can be very difficult to change when packaging an application. There are a few different ways of handling it, but generally, you need to make sure the user you want is signed in, create a package that sets the key, and run the package as the user, instead of local system. These HKCU keys make handling these packages much more difficult since you can't just schedule the package in Landesk and walk away. You need to verify if the user is logged into the computer to make sure they get the registry settings they need.

Best available workaround

The following bat script (from the resource page linked at the bottom) will change a registry key for all existing users as well as any future users who log into the computer later. The advantage of this script is it removes the concern about running the package as a specific user or making sure the user is signed in.

REM Modify a registry key in for all logged in users
REM Also modify it in the .DEFAULT hive so future users get it.
REM
REM Copyright Jared Barneck
REM

GOTO main

:modkey
  REM %1 is the value of %a that is passed.
  REG Add HKU\%1\SomeRegKey
  REG ADD HKU\%1\SomeRegKey /v SomeDWORD /t REG_DWORD /d 1
  REG ADD HKU\%1\SomeRegKey /v SomeString /t REG_SZ /d "Hello, World"
  REM Going to :end here only ends this instance of the call to the 
  REM :modkey label. It does not end the whole batch file.
GOTO end

:main
  FOR /F "tokens=2* delims=\" %%a IN ('REG QUERY HKU ^|Findstr /R "DEFAULT S-1-5-[0-9]*-[0-9-]*$"') DO CALL :modkey %%a
  REM Going to :end here ends the whole batch file.
GOTO end

:end

Resources

http://community.landesk.com/support/docs/DOC-2417

Information on the Tufts IT Knowledgebase is intended for IT Professionals at Tufts.
If you have a question about a Tufts IT service or computer/account support, please contact your IT support group.