Active Setup (Example)

The following script registers a new Active Setup script that runs “reg.exe import user.reg” for each user.

Tested with opsi 4.0.4
Tested with opsi-winst 4.11.4.3
By holgerv 2014-08-06

Active Setup is a mechanism in Microsoft Windows to enforce a script (or multiple scripts) to be executed for each single user who logs on into Windows exactly once. It works for local profiles and for roaming profiles as well.

It is convenient for changing user profiles.

Active Setup entrys have a version number, so you can enforce that the actual version of your Active Setup script is executed for each user.

Limitation: Active Setup doesn't work for Citrix published applications automatically, because Active Setup is run by explorer.exe.

Weblinks:

Tree:

CLIENT_DATA
  ├ delsub.ins
  ├ setup.ins
  ├ uninstall.ins
  └ user.reg

setup.ins

[Actions]
SetLogLevel = 6
 
DefVar $ProductId$
DefVar $ProgramPath$
DefVar $RegFileName$
DefVar $ScriptName$
 
Set $ProductId$ = "ActiveSetupExample"
Set $ProgramPath$ = "%ProgramFilesSysnativeDir%" + "\" + $ProductId$
Set $RegFileName$ = "user.reg"
Set $ScriptName$ = "ActiveSetupScript.cmd"
 
Message "Uninstall this software before reinstallation (just in case it's installed already) ..."
Sub "%ScriptPath%\delsub.ins"
 
Message "Copy .reg file to program directory ..."
Files_Copy_Reg_File /SysNative
 
Message "Create script that shall be executed once by/for each single user ..."
DosInAnIcon_Create_Script /SysNative
 
Message "Create ActiveSetup entry for the new script ..."
Registry_Enable_ActiveSetup_Script /SysNative
 
 
[Files_Copy_Reg_File]
copy "%ScriptPath%\$RegFileName$" "$ProgramPath$"
 
[DosInAnIcon_Create_Script]
echo reg.exe import "$ProgramPath$\$RegFileName$" > "$ProgramPath$\$ScriptName$"
 
[Registry_Enable_ActiveSetup_Script]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\$ProductId$]
set "" = "$ProductId$"
set "StubPath" = '"$ProgramPath$\$ScriptName$"'
set "Version" = "1,0,0,0"

uninstall.ins

[Actions]
SetLogLevel = 6
 
DefVar $ProductId$
DefVar $ProgramPath$
DefVar $RegFileName$
DefVar $ScriptName$
 
Set $ProductId$ = "ActiveSetupExample"
Set $ProgramPath$ = "%ProgramFilesSysnativeDir%" + "\" + $ProductId$
Set $RegFileName$ = "user.reg"
Set $ScriptName$ = "ActiveSetupScript.cmd"
 
Message "Uninstall " + $ProductId$
Sub "%ScriptPath%\delsub.ins"

delsub.ins

Message "Disable ActiveSetup entry ..."
; There's no "If (RegKeyExists(...))" in opsi, so just delete the registry key and get a log file warning if it doesn't exist
Registry_Disable_ActiveSetup_Script /SysNative
 
Message "Delete ActiveSetup script ..."
If (FileExistsSysNative($ProgramPath$ + "\" + $ScriptName$))
        Files_Delete_ActiveSetup_Script /SysNative
endif
 
Message "Delete reg file ..."
If (FileExistsSysNative($ProgramPath$ + "\" + $RegFileName$))
        Files_Delete_Reg_File /SysNative
endif
 
 
[Registry_Disable_ActiveSetup_Script]
DeleteKey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\$ProductId$]
 
[Files_Delete_ActiveSetup_Script]
Delete "$ProgramPath$\$ScriptName$"
 
[Files_Delete_Reg_File]
Delete "$ProgramPath$\$RegFileName$"

You will also need a user.reg which contains the changes in HKCU that you want to import for each user.