3
有沒有辦法檢查用戶當前具有哪些背景,然後根據其內容進行更改?例如:我想在白天時間使用白色背景,在夜間使用黑色背景。運行腳本將檢查當前背景,如果它是白色的,則會切換到黑色背景,如果是黑色,則會切換到白色。用於切換桌面背景的Windows批處理腳本
我有點不熟悉Windows批處理腳本,我正在尋求一些關於如何完成上述任務的提示和建議。以下是我已經能夠到目前爲止發現:
@echo off
call :quiet>nul 2>&1
goto :EOF
:quiet
:: Configure Wallpaper
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "%SystemRoot%\energybliss.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 2
:: Configure the screen saver.
:: REG ADD "HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\scrnsave.scr"
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
:: Set the time out to 900 seconds (15 minutes).
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaveTimeOut /T REG_SZ /F /D 900
:: Set the On resume, password protect box
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaverIsSecure /T REG_SZ /F /D 1
:: Remove the user's ability to see the Screen Saver, background, and appearance tabs of Display Properties.
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispScrSavPage /T REG_DWORD /F /D 1
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispBackgroundPage /T REG_DWORD /F /D 1
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispAppearancePage /T REG_DWORD /F /D 1
:: Make the changes effective immediately
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
這幾乎可行,但似乎有一個問題。有時(實際上大多數情況下)腳本必須在背景更改之前運行多次。註冊表值似乎會改變,但背景保持不變。 '%SystemRoot%\ System32 \ RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters'該行假設無需註銷就可以更改背景,但由於某種原因它不起作用。 –
確保您正在運行具有相應權限的rundll32.exe ...它可能是UAC(用戶帳戶控制)停止(=攔截)該系統調用工作。 ;) – 2011-12-20 16:23:07