Set-ActiveSetup and Remove-ActiveSetup: Per-user changes (as requested) Part2

Topics: Archive - Toolkit Extensions
Sep 2, 2014 at 10:51 PM
Edited Nov 6, 2014 at 10:09 PM
Version: 0.5 (2014 Sept 02) -Posts are limited to 10000. ("Content has been shortened to 10000 characters.")
Version: 0.6 (2014 Sept 17)

``` Function Remove-ActiveSetup {
Remove an Active Setup entry in the registry
Version: 0.6 - Author: CodePlex's That_annoying_guy - 2014 Sept 17 - BETA USE AT YOUR OWN RISK!!

Active Setup is a built-in feature of Windows to handle per-user changes
A registry key is created in HKLM and *as users login*, the user runs the "Stub" in the StubPath value and copies the Version value to HKCU in a matching Key
If the Version value in HKLM is higher than the version value in HKCU, the StubPath is ran again when a user logs in.   

-Removes Active Setup Key from HKLM. Does NOT touch Active Setup Keys in HKCU unless you use -purge
-This is complimentary to Set-ActiveSetup
Remove-ActiveSetup [-Key "MyCustomKeyName"] [-Purge]
Remove-ActiveSetup -Key "MyCustomKeyName"
Remove-ActiveSetup -Purge
-Optional Name of registry Key name used for the Active Setup.
-Defaults to $installName if blank
TODO: Add 32/64Bit support. (Current version is 64-bit only but I've been told this is important)
Depends on TK's Remove-RegistryKey and Write-Log functions



[String]$ActiveSetupKey="HKLM:\Software\Microsoft\Active Setup\Installed Components\$Key"
[String]$HKCU_ACTIVESETUPKEY="HKCU:\Software\Microsoft\Active Setup\Installed Components\$Key"

Write-Log "Removing Active Setup Key $ActiveSetupKey..."

Remove-RegistryKey -Key $ActiveSetupKey -Recurse $true -ContinueOnError $false #Fails if Key is already deleted = TK 3.20 Bug

Remove-RegistryKey -Key $ActiveSetupKey -Recurse $true #Fails if SubKeys do not exist or already deleted = TK 3.20 Bug

Remove-RegistryKey -Key $ActiveSetupKey

If ($Purge) {
    Write-Log "Removing $ActiveSetupKey on all other User hives on machine..."
    #Cleans out previous ActiveSetup Key in each user profile (for overkill lovers)
    Remove-RegistryKeyFromAllHives $ActiveSetupKey

Write-Log "Remove-ActiveSetup done.`n"

endregion ActiveSetup```