如果您需要更改个别外观选项(如窗口颜色),您可以在HKEY_CURRENT_USER\Control Panel\Appearance 和HKEY_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。