【问题标题】:Modify XP theme (appearance&color scheme) from a vbscript从 vbscript 修改 XP 主题(外观和配色方案)
【发布时间】:2009-03-30 13:20:00
【问题描述】:

有人知道如何使用 VBScript 修改 Windows XP 的外观和配色方案吗?

我有一个用 Visual C++ 编写的应用程序,需要正确显示 Windows XP 外观(非经典),我想从安装中设置此属性。

我使用 InstallShield 来制作安装程序,并使用 VBScript 来执行一些自定义操作。因此,如果我可以在 Visual Basic 中创建一个脚本来更改此属性,那就太好了。

【问题讨论】:

    标签: vbscript windows-xp installation themes


    【解决方案1】:

    应该这样做:

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

    但是,您仍然需要让用户单击“确定”或使用其他实用程序为您执行此操作。

    【讨论】:

      【解决方案2】:

      如果您需要更改个别外观选项(如窗口颜色),您可以在HKEY_CURRENT_USER\Control Panel\AppearanceHKEY_CURRENT_USER\Control Panel\Colors 键下修改相应的注册表值。例如,此代码会将窗口背景颜色更改为奶油色:

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

      但请注意,Windows 可能仅在重新启动后才会应用注册表更改。


      如果您需要加载准备好的.theme文件,可以使用以下代码:

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

      虽然,正如 sascha 所指出的,这只会打开显示属性对话框并选择指定的主题;您仍然需要用户单击确定或按 Enter。可以使用WshShell.SendKeys 方法从脚本代码模拟按键:

      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"
      

      但是这种方法是不可靠的,因为用户可以点击其他地方,所以 Enter 会转到另一个窗口。此外,显示属性对话框标题取决于区域设置。

      另一种选择是使用从 Windows XP SP1 开始的 themeui.dll 库提供的 Theme.Manager API,但它似乎不适用于 XP SP2。无论如何,你可以找到示例代码here

      【讨论】:

        【解决方案3】:

        我所做的是创建一个 c++ dll,用作 Install Shield 中的自定义操作。在这个 dll 中,我使用 uxtheme.dll 将 luna.msstyle 文件设置为主题。这是完成工作的函数:

        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;
        }
        

        它并不完美,但它可以满足我的需求。

        我希望这可以对其他人有所帮助...如果您有任何疑问,请随时问我。

        干杯。

        【讨论】:

          【解决方案4】:
          'Script name: yourtheme.vbs
          
          'Object: Automate without command prompt the application of a Windows Theme by a VB script
          
          '
          
          'SCRIPT CONTENTS:
          
          'Define Variables : 
          
              Set ShellApp = CreateObject("Shell.Application")
              Set WsShell = CreateObject("Wscript.Shell")
          
          
          '
          
          'Define path for your file theme (put it on a network share and don't forget to apply "read and execute" ACL for your Users)
          
              Theme = "typeyoursharepath\typeyourtheme.theme"
              Theme = """" + Theme + """"
          
          
          'Open Display Properties Windows, Select your theme and apply with keep focus on Windows
          
              ShellApp.ControlPanelItem cstr("desk.cpl desk,@Themes /Action:OpenTheme /file:" & Theme)
              Wscript.Sleep 100
              WsShell.SendKeys "{ENTER}"
              While WsShell.AppActivate ("Display Properties") = TRUE
              WsShell.AppActivate "Display Properties"
              Wend
          
          
          'END OF SCRIPT 
          

          在 Windows XP 和 Windows Server 2003R2 X86 上成功应用,在 Citix XenApp 4.6FP7(操作系统:W2003R2X86 SP2)下应用 Windows Embedded 主题,蓝色背景颜色更亮。

          在 Citrix 会话用户上看起来很棒!

          在用户登录 Citrix XenApp 时集成在用户配置 GPO 中。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-04-15
            • 1970-01-01
            • 2020-07-22
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多