views:

1787

answers:

3

Does anybody know how to modify Windows XP appearance and color scheme using VBScript?

I have an application written in Visual C++ that needs Windows XP appearance (not classic) to be properly displayed and I want to set this properties from the Installation.

I use InstallShield to make the installer and VBScript to perform some custom actions. So it would be great if I can create a script in visual basic to change this properties.

+2  A: 

This should do it:

rundll32 shell32.dll,Control_RunDLL desk.cpl desk,@themes /Action:OpenTheme /File:"%WinDir%\Resources\Themes\Luna.theme"

However you still need to get the user to click "OK" or use another utility to do this for you.

sascha
+1  A: 

If you need to change individual appearance options (like window colors), you can modify the appropriate registry values under the HKEY_CURRENT_USER\Control Panel\Appearance and HKEY_CURRENT_USER\Control Panel\Colors keys. For example, this code will chamge the window background color to cream:

Set oShell = CreateObject("WScript.Shell")
oShell.RegWrite path & "HKCU\Control Panel\Colors\Window", "255 251 240", "REG_SZ"

Note, however, that Windows will probably apply the registry changes only after reboot.


If you need to load a ready .theme file, you can use the following code:

Const Theme = "C:\MyTheme.theme"

Set oShellApp = CreateObject("Shell.Application")
oShellApp.ControlPanelItem "desk.cpl desk,@Themes /Action:OpenTheme /file:""" & Theme & """"

Although, as sascha has pointed out, this will only bring up the Display Properties dialog with the specified theme selected; you still need the user to click OK or press Enter. It's possible to simulate key presses from script code using the WshShell.SendKeys method:

Set oShell = CreateObject("WScript.Shell")

' Wait until the Display Properties dialog is opened
While Not oShell.AppActivate("Display Properties")
  WScript.Sleep 500
Wend

' Send the Enter key to close the dialog and apply the theme
Do
  oShell.SendKeys "~"
  WScript.Sleep 500
Loop While oShell.AppActivate "Display Properties"

But this approach is unreliable, because the user could click somewhere else so Enter would go to another window. Also, the Display Properties dialog caption is locale-dependent.

Another option would be to use the Theme.Manager API provided by the themeui.dll library starting from Windows XP SP1, but it doesn't seem to work on XP SP2. Anyway, you can find sample code here.

Helen
A: 

What I did was creating a c++ dll that I use as a Custom Action in Install Shield. In this dll I use the uxtheme.dll to set the luna.msstyle file as a theme. This is the function that does the work:

bool SetVisualStyle()
{
    TCHAR szUxTheme[MAX_PATH+1];
    UINT nSize = ::GetSystemDirectory( szUxTheme,
             MAX_PATH);
    szUxTheme[nSize] = '\0';

    wcscat_s( szUxTheme,
       MAX_PATH - nSize,
       L"\\uxtheme.dll");

    HMODULE hModule = ::LoadLibrary(szUxTheme);
    if(!hModule)
    {
     return false;
    }

    typedef int (__stdcall *SETVISUALSTYLE) ( LPCWSTR szTheme, 
               LPCWSTR szScheme, 
               LPCWSTR szFontType, 
               int nReserved);
    SETVISUALSTYLE pFnSetVisualStyle;
    pFnSetVisualStyle = (SETVISUALSTYLE)GetProcAddress( hModule,
                 MAKEINTRESOURCEA(LOWORD(65)));
    if(pFnSetVisualStyle)
    {
     pFnSetVisualStyle( L"C:\\WINDOWS\\Resources\\Themes\\Luna\\luna.msstyles", 
          L"NormalColor",
          L"NormalSize",
          1|32);
    }

    ::FreeLibrary(hModule);
    return true;
}

It's not perfect but it does what I need.

I hope that this can help someone else...if you have any doubt don't hesitate in asking me.

Cheers.

Javier De Pedro