Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to have a script that would change the current theme of Windows 7. I found the registry entry where this stored, but I apparently need to take some further action to get Windows to load the theme. What should I do?

Here is the script that I'm trying to use, but it isn't working (registry updated, but theme not changed):

######################################
# Change theme by updating registry. #
######################################

# Define argument which defines which theme to apply. 
param ( [string] $theme = $(Read-Host -prompt "Theme") )

# Define the themes we know about.
$knownThemes = @{ "myTheme" = "mytheme.theme"; "alien" = "oem.theme" }

# Identify paths to user themes.
$userThemes = " C:\Users\yoda\AppData\Local\Microsoft\Windows\"

# Get name of theme file, based on theme provided
$themeFile = $knownThemes["$theme"]

# Build path to theme and set registry.
$newThemePath = "$userThemes$themeFile"
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\"
Set-ItemProperty -path $regPath -name CurrentTheme -value $newThemePath

# Update system with this info...this isn't working!
rundll32.exe user32.dll, UpdatePerUserSystemParameters
share|improve this question
up vote 2 down vote accepted

Have a look at the Stack Overflow question How do I change the current Windows theme programatically? dealing with the same issue. It seems like most commenters think you shouldn't be doing this at all (you may choose to ignore them). The other suggestions can be easily turned into a PowerShell script - just call the appropriate API functions.

share|improve this answer

I've solve the problem with this code (tested in Windows 7 64bits)

# definition de la fonction native Windows permettant le test d'activation d'Aero
$def = @"

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern bool DwmIsCompositionEnabled();

"@
# chargement de la fonction native dans un namespace personnel
Add-Type -Namespace MaifCode -Name Aero -MemberDefinition $def


# fonction qui check si Aero est desactive ou non
function Check-Is-Aero{
    [CmdletBinding()]
    param()
    Write-Verbose "[$([DateTime]::Now)] ==> Test de la presence du mode Aero pour la session utilisateur $env:USERNAME"
    if([MaifCode.Aero]::DwmIsCompositionEnabled()){
        Write-Verbose "[$([DateTime]::Now)] ==> Aero actif pour la session utilisateur $env:USERNAME"
        return $true
    }else{
        Write-Verbose "[$([DateTime]::Now)] ==> Aero inactif pour la session utilisateur $env:USERNAME"
        return $false
    }
}

# fonction qui test si Aero est actif et le desactive dans ce cas
function Disable-Aero{
    [CmdletBinding()]
    param()
    # test si aero actif
    If(Check-Is-Aero) {
        Write-Verbose "[$([DateTime]::Now)] ==> Tentative de desactivation du mode Aero pour la session utilisateur $env:USERNAME"
        # desactivation du mode aero en passant sur le them par defaut
        try{
            Start-Process -Wait -FilePath "rundll32.exe" -ArgumentList "$env:SystemRoot\system32\shell32.dll,Control_RunDLL $env:SystemRoot\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""C:\Windows\Resources\Ease of Access Themes\basic.theme"""
        }
        catch [exception]
        {
            # si erreur alors on sort et on affiche le message d'erreur
            Write-Error "Erreur dans l'execution de la desactivation du mode Aero : $error"
            exit -1
        }
        Write-Verbose "[$([DateTime]::Now)] ==> Desactivation du mode Aero pour la session utilisateur $env:USERNAME terminee"
    }else{
        Write-Verbose "[$([DateTime]::Now)] ==> sortie du script sans action"
    }
}

# execution du code de desactivation
Disable-Aero -Verbose
# on sort
exit 0
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.