有人知道如何使用 VBScript 修改 Windows XP 的外观和配色方案吗?
我有一个用 Visual C++ 编写的应用程序,需要正确显示 Windows XP 外观(不是经典),我想从安装中设置此属性。
我使用 InstallShield 来制作安装程序,并使用 VBScript 来执行一些自定义操作。因此,如果我可以在 Visual Basic 中创建一个脚本来更改此属性,那就太好了。
有人知道如何使用 VBScript 修改 Windows XP 的外观和配色方案吗?
我有一个用 Visual C++ 编写的应用程序,需要正确显示 Windows XP 外观(不是经典),我想从安装中设置此属性。
我使用 InstallShield 来制作安装程序,并使用 VBScript 来执行一些自定义操作。因此,如果我可以在 Visual Basic 中创建一个脚本来更改此属性,那就太好了。
这应该这样做:
rundll32 shell32.dll,Control_RunDLL desk.cpl desk,@themes /Action:OpenTheme /File:"%WinDir%\Resources\Themes\Luna.theme"
但是,您仍然需要让用户单击“确定”或使用其他实用程序为您执行此操作。
如果您需要更改个别外观选项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 会转到另一个窗口。此外,“显示属性”对话框标题取决于区域设置。
另一种选择是使用Theme.Manager
从 Windows XP SP1 开始的 themeui.dll 库提供的 API,但它似乎不适用于 XP SP2。无论如何,您可以在此处找到示例代码。
我所做的是创建一个 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;
}
它并不完美,但它可以满足我的需求。
我希望这可以帮助其他人......如果您有任何疑问,请不要犹豫问我。
干杯。
'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 中。